jQuery 在div中加载html内容

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/18909567/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-26 22:44:48  来源:igfitidea点击:

Load html content in div

jqueryhtmlloadjquery-load

提问by Sowmya

I am trying to load the content from another html file into my existing html file using jquery .load

我正在尝试使用 jquery 将另一个 html 文件中的内容加载到我现有的 html 文件中 .load

But unfortunately it is not loading the content.

但不幸的是它没有加载内容。

Please suggest me with the proper solution.

请给我建议正确的解决方案。

Here is my existing html and jquery to load content from external HTML file

这是我现有的用于从外部 HTML 文件加载内容的 html 和 jquery

    <!DOCTYPE html>
    <html lang="en">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>Review</title>
    <script src="http://code.jquery.com/jquery-1.9.1.js"></script>
    </head>
    <body>
            <ul class="reviews" id="revw">

            </ul>
    </div>
    <script>
    function check(){
$( "#revw" ).load( "review_list.html #test" );
}
    </script>
    </body>
    </html>

Page from which we need to load the content

我们需要从中加载内容的页面

<html>
<head></head>
<body>
<div id='test'>
 Load this content to the id="revw" div.
</div>
</body>
</html>

回答by techfoobar

You are not calling the function check()anywhere.

您没有在check()任何地方调用该函数。

Try this:

尝试这个:

...
<script>
function check() {
    $( "#revw" ).load('review_list.html #target');
}
$(document).ready(function() {
    check(); // call the function
});
</script>
...

回答by raduns

Try this using $.get.

试试这个使用$.get.

 $(document).ready(function() {
    $.get('review_list.html')
             .success(function(data) {
                 $('#revw').html(data);
             });
    });

Your HTML page

您的 HTML 页面

<div id='test'>
 Load this content to the id="revw" div.
</div>

回答by seshan

Please Refer this link :

请参考此链接:

Load one page in to another using Jquery

使用 Jquery 将一个页面加载到另一个页面

It has a detailed explaination of your problem

它详细说明了您的问题

Delayed loading of a html page using jquery

使用 jquery 延迟加载 html 页面

Both these will solve the probelm.

这两个都可以解决问题。