【发布时间】:2017-01-07 13:54:27
【问题描述】:
我正在尝试使用 jQuery 从另一个 html 文件的内容加载 html 文件的一部分。这些代码适用于 Mozilla Firefox,但不适用于 Google Chrome 或 Windows Internet Explorer。在最后两个浏览器中,页面保持原样。我做错了什么?
index.html
<html>
<head>
<script src="jquery-3.1.1.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$("#clickhere").click(function(){
$("#partialdisplay").load("sourcepage.html");
});
});
</script>
</head>
<body>
<div id="header">
This is the header.
<a href="#" id="clickhere">Click here</a>
</div>
<div id="partialdisplay">
<!--Content from other page will be loaded here -->
</div>
<div id="footer">
This is the footer.
</div>
</body>
</html>
sourcepage.html
<html>
<head>
</head>
<body>
<div id="partialdisplay">
This part will be called back to index.html.
</div>
</body>
</html>
【问题讨论】:
-
只将
<div id="partialdisplay"> This part will be called back to index.html. </div>放入您的sourcepage-html 文件 -
应该可以正常工作...开发工具控制台中是否有任何错误?请注意,您将在页面中拥有重复的 ID
-
你只是指
src="jquery-3.1.1.js"。尝试在src参考中给出完整的路径,以http://... 开头。 -
您是否从硬盘测试此代码?或者你正在使用服务器?只有 Firefox 会从您的硬盘加载文件。
标签: javascript jquery html