Jquery .load() 函数不加载 html 评论标签

标签 jquery html

我正在使用 .load() Jquery 函数,将 html 标签包含在另一个 html 文件中。 代码示例:

a.html:

<html> 
<head> 
    <script src="jquery.js"></script> 
    <script> 
        function loadContent() 
        { 
            $("#includedContent").load("b.html"); 
        } 
    </script> 
</head> 
<body> 
   <div id="includedContent"></div> 
   <script>loadContent()</script> 
</body>

b.html:

<!--Include  it-->
<p> This is my include file </p>

当我在浏览器中打开 a.html 并单击“查看源代码”时,我看不到

<!--Include  it-->

这是为什么呢? 我需要它来追踪东西。

如果你制作一个简单的 html 文件:

<html>
<body>
    <!-- Hello -->
    <p>Hello world </p>
</body>
</html>

在浏览器中打开它,单击“查看源代码”。你可以看到

<!-- Hello -->

为什么我们使用 .load() 时看不到评论???

最佳答案

你用的是什么浏览器? IE 不会更新 DOM(在查看源代码/开发人员工具 View 中)以响应 ajax 请求,如果您使用他们的开发人员工具查看页面,Chrome 会更新

然后加载开始工作,这只是关于您尝试查看评论的方式。浏览器如何处理更新其“查看源代码”以响应动态页面事件是特定于浏览器的,如果您依靠其他人来操作 DOM,然后查看页面源代码以查看更改,您可能需要重新考虑您的策略。

评论应该在div的Html中:

<script> 
        function loadContent() 
        { 
            $("#includedContent").load("b.html", function() { alert($("#includedContent").html() }); 
        } 
    </script> 

您可能需要想出一个显示评论的新方案。也许将它们添加到一个隐藏的 div 中,并允许您的 adv 人员(无论他们是谁)点击一个按钮来查看它们。

关于Jquery .load() 函数不加载 html 评论标签,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9054669/

相关文章:

javascript - 如何使 <select> 元素不选择默认选择的第一个选项?

html - 文本不会出现在页眉上

javascript - 使用 JavaScript 获取元素的串联文本

javascript - 自动调整所有屏幕的弹出框

jquery - ASP.NET MVC : Values sent by jQuery ajax is not being bound to the view model by the action

php - 如何使用 PHP 正确检索 JSON 字符串?

html - 修复了在 html 表格标题处滚动而不影响标题大小

html - 对齐 rails form_for 与 bootstrap 集成的按钮

html - 即使应用了 reset.css,不同浏览器的输出也不同

javascript - jQuery AJAX 在成功时将函数作为数据返回