简体   繁体   English

如何从我的主要html的另一个html文件中加载某些内容?

[英]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轻松实现。

AJAX Introduction AJAX简介

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.

相关问题 如何将html页面中的div内容加载到主页上的div中? - How can I load div content from html pages into a div on main page? 从某些不同的页面链接返回时,如何编译html内容? - How can I compile my html content when coming back from some different page links? 如何从另一个使用jQuery load()加载的html页面执行写在主html文件中的脚本 - How to execute script written in main html file from another html page loaded using jquery load() 如何使用PHP将HTML内容保存并加载到文件中 - How can I save and load the content of HTML into the file using PHP 如何从 partial.hbs 更改 main.hbs 文件的 html 标题? - How can I change the html title of my main.hbs file from a partial.hbs? 如何将数据从JSON文件加载到HTML页面? - How can I load data from my JSON file to my HTML page? 如何使用jQuery load()方法将从txt文件加载的链接设置为HTML样式? - How can I style links I loaded from a txt file with the jQuery load() method into my HTML? HTML将html文件中div的内容加载到另一个html文件中 - HTML load the content of a div in a html file into another html file 如何将单独的 html 页面加载到我的主 index.html 中? 我想可以通过使用 jquery 选择元素 id 来完成 - How can I load a separate html page into my main index.html? I imagine it can be done by selecting an element id with jquery 如何将模板从html文件加载到Angular应用中? - How can I load templates from an html file into my Angular app?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM