这是相关的代码:
<body>
<h1>Music Nation</h1>
<div id="navBar">
<ul>
<li>
<a href="Welcome.html">Home</a>
</li>
<li>
<a href="Trance.html" id="tranceGen">Trance</a>
<ul>
<li>
<a href="MS.html" id="artistMS">Markus Schulz</a>
</li>
</ul>
</li>
</ul>
</div>
<div id="pjax-container">
some text that should be replaced...
</div>
<script>
$(document).ready(function () {
$("#tranceGen").click(function () {
e.preventDefault();
$("#pjax-container").load("Trance.html #pjax-container");
});
});
</script>
</body>
就我在互联网上读到的而言,通过使用它,它应该只替换页面的某个部分而不重新加载整个页面,但由于某种原因它不起作用。它仍然加载整个页面。
我已经阅读了如何使用它:http : //api.jquery.com/load/我还阅读了一些教程,我在这里阅读了关于同一主题的其他问题,但我尝试的任何内容似乎都不起作用.
我还尝试了我在另一个教程中读到的其他内容,通过添加“e.preventDefault();”来删除默认操作(加载我假定单击的页面),但这也没有效果。
我究竟做错了什么?我想在当前页面的“#pjax-container”的“Trance.html”页面中加载“#pjax-container”的内容而不重新加载整个页面。如果有某种相关性,我将在 Windows 7 上使用 Visual Studio 2017。
另外,在“头部”部分,我有:
<script type="text/javascript" src="Scripts/jquery.pjax.js"></script>
<script src="Scripts/jquery-1.9.1.js"></script>
<div id="#pjax-container">
some text that should be replaced...
</div>
用 pjax-container 替换 id
<div id="pjax-container">
some text that should be replaced...
</div>
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句