gpt4 book ai didi

javascript - 如何在不重新加载整个网站的情况下替换网站的一部分?

转载 作者:行者123 更新时间:2023-11-28 04:41:23 25 4
gpt4 key购买 nike

相关代码如下:

<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();”来删除默认操作(加载我认为单击的页面),但这也没有效果.

我做错了什么?我想将“Trance.html”页面中“#pjax-container”的内容加载到当前页面的“#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>

关于javascript - 如何在不重新加载整个网站的情况下替换网站的一部分?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43736181/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com