在div中显示html文件 [英] display html file in a div

查看:2249
本文介绍了在div中显示html文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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.

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

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.

我试过了

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

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

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)

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

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

推荐答案

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

$('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>

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

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

这篇关于在div中显示html文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆