您查询的关键词是:div内 显示 一个 html 
下面是原始网址 https://www.it1352.com/876090.html 在 2020-09-25 07:34:58 的快照。

360搜索与该网页作者无关,不对其内容负责。

在div中显示html文件 - IT屋-程序员软件开发技术分享社区

在div中显示html文件(display html file in a div)

1152 IT屋

I've been trying to search for a way to do this as I'm sure there's hundreds of websites explaining it but I just can't word it right so all my searches come up with something else.

So I'm sorry if this has been asked many times before.

Anyway, what I'm trying to do is load a page 'page.html' inside a div. The page just has text and nothing else. So instead of using an iframe I want to load this page inside the div so that it'll only show the text that is on that page.

I've tried a few different things that I found during my search like;

$(document).ready(function() {
$("div").load("page.html")
});

But for some reason that method changed all my text on the page instead of being inside that div. (I'm pretty horrible at coding so I've probably gone wrong somewhere with that method)

So can anyone suggest for a way to load the content of a page inside a div not using an iframe.

解决方案

$('div') is going to target more than you're looking for. If you're trying to load the content into a specific div element, give it an ID and target it that way.

<div id="pageContent"></div>

$(document).ready(function() {
$('#pageContent').load('page.html');
}

我一直在试图寻找一种方法来做到这一点,因为我确信有数百个网站在解释它,但我不能说出正确的答案,所以我的所有搜索都有其他的东西。



所以我很抱歉,如果这已被问了很多次。



无论如何,我想要做的是在div中加载页面'page.html'。该页面只有文本,没有别的。因此,我不想使用iframe,而是希望在div内加载此页面,以便它只显示该页面上的文本。



我试过了



 $(document).ready(function(){
) $("div")。load("page.html")
});


但由于某种原因,该方法在页面上更改了所有文本,而不是在该div内。 (我在编码时非常可怕,所以我可能在某个地方出现了这种方法)



那么任何人都可以提出一种加载页面内容的方法一个div不使用iframe。

解决方案

$('div')会比你想要的更多的目标。如果您要将内容加载到特定的 div 元素中,请为其指定一个ID并将其定位。



< div id ="pageContent">< / div>

 < $ c $> $(document).ready(function(){
$('#pageContent')。load('page.html');
}

本文地址:IT屋 » 在div中显示html文件