[英]how can i load some content from another html file my main html?
I want to add specific content from another HTML page into my main HTML. 我想将另一个HTML页面中的特定内容添加到我的主HTML中。 I am trying using .load by jquery it is work but run just in firefox, I want some method that works in other browsers like chrome.
我正在尝试通过jQuery使用.load,但它只能在firefox中运行,我想要一些可以在其他浏览器(例如chrome)中使用的方法。 I have two HTML I want to insert div with id=2 from second html into first HTML to div with id=ok?
我有两个HTML,我想将id = 2的div从第二个html插入第一个HTML到id = ok的div? could you please help me?
请你帮助我好吗? main HTML:
主要HTML:
<html>
<head>
<title></title>
</head>
<body>
<div id="ok"></div>
</body>
</html>
second html: 第二个html:
<html>
<head>
<title></title>
</head>
<body>
<div id="1">one</div>
<div id="2">two</div>
<div id="3">three</div>
</body>
</html>
You are looking for what is called AJAX. 您正在寻找所谓的AJAX。 this can be achieve with pure JS or in my opinion more easily with JQuery.
这可以通过纯JS来实现,或者在我看来可以通过JQuery轻松实现。
You can use an ajax call to load the file as text.Then Append the obtained content into required div with jquery wrapper around it. 您可以使用ajax调用以文本形式加载文件,然后将获取的内容附加到所需的div中,并带有jquery包装器。
$.ajax({url: "second.html", success: function(result){
$("#ok").append($(result));
}});
And of course it should be in document ready event 当然应该在文档准备就绪事件中
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.