使用javascript在URL中加载页面数据
我有一个HTML页面,我想在使用JavaScript点击一个类时加载它。我正在考虑使用iframe获取HTML。此页面包含覆盖格式的内容 我已经使用了jQuery的.load函数,但它没有做任何事情。我正在工作的页面都在同一个域中,所以我希望该页面已经加载 我怎样才能做到这一点使用javascript在URL中加载页面数据,javascript,jquery,iframe,Javascript,Jquery,Iframe,我有一个HTML页面,我想在使用JavaScript点击一个类时加载它。我正在考虑使用iframe获取HTML。此页面包含覆盖格式的内容 我已经使用了jQuery的.load函数,但它没有做任何事情。我正在工作的页面都在同一个域中,所以我希望该页面已经加载 我怎样才能做到这一点 $(".popup-layout").click(function() { // I want to load an iframe here. Where should that iframe sit on the c
$(".popup-layout").click(function() {
// I want to load an iframe here. Where should that iframe sit on the current page with diplay:none.
});
$‘结果’是一个?无法通过jquery.load填充iframe。事实上,你不需要。您可以使用简单的这里有3种方法可以帮助您实现这一目标: 通过更改页面的src在上加载页面: 通过HTTP请求加载页面并更改现有元素的innerHTML: 使用文档对象的位置属性:
我会在iframe上使用ajax加载的内容,不过这只是我的观点
$(".popup-layout").click(function() {
$.get("yourFile.html", function(data){
$("#Content").html(data); // the div to load content in
});
});
你能发布你的标记吗?或者是一把小提琴,我希望在点击class.popup布局时,我可以使用javascript获取localhost:8080/abc.html页面。我只得到了这个javascript。实际上,你可以得到它的可能副本。使用.attr您的意思是设置iframe的src属性?当然可以这样做,但这与jquery.load无关
var req = new XMLHttpRequest();
req.open('GET', 'http://www.mozilla.org/', true);
req.onreadystatechange = function (aEvt) {
if (req.readyState == 4 && req.status == 200) {
YourElementId.innerHTML = req.responseText;
}
};
req.send(null);
document.location = 'http://example.com'
$(".popup-layout").click(function() {
$.get("yourFile.html", function(data){
$("#Content").html(data); // the div to load content in
});
});