我做了一个代码,点击不同的链接,具体的部门会分别改变。
第一个文件是: index.html
<div class="wrapper">
<div class="grid3 first">
<ul class="categories">
<li><a id="Engineering">Aerospace</a></li>
<li><a id="Productive">Automotive</a></li>
<li><a href="Chemicals">Chemicals</a></li>
</ul>
</div>
<section id="neeraj_content">
<div class="grid19" id="Engineering" >
<h2>Grow service revenue with world-class<br/>
lifecycle service and support.</h2>
<p>some displaying content here that appears in the division grid19 </p>
</div>
</section>
</div>
在这个索引文件中我有一个js
<script>
$(document).ready(function(){
$('#neeraj_menu ul li a').click(function(){
$('#neeraj_content').load('division.html #' + $(this).attr('href'));
return false;
});
});
</script>
现在我制作了另一个名为 division.html 的 html 文件,其中必须出现在分区 grid19 中的其他内容必须出现在该特定位置
<div class="grid19" id="Engineering" >
<h2>Grow service revenue with world-class<br/>
lifecycle service and support.</h2>
<p>some displaying content here that appears in the division grid19 </p>
</div>
</section>
</div>
<div class="grid19" id="Productive" >
<h2>Grow service revenue with world-class<br/>
lifecycle service and support.</h2>
<p>some displaying content here that appears in the division grid19 </p>
</div>
</section>
</div>
<div class="grid19" id="Chemicals" >
<h2>Grow service revenue with world-class<br/>
lifecycle service and support.</h2>
<p>some displaying content here that appears in the division grid19 </p>
</div>
</section>
</div>
现在,点击生产或化学品时,部门的内容必须更改。我在更改它时遇到问题。它实际上访问了 division.html 文件中的特定 id。它不工作。里面有问题。我不知道错误在哪里。 它也确实发生了变化,因为我之前已经厌倦了它并且它起作用了,现在我已经忘记了它第一次是怎么做的。
最佳答案
您正在引用:
$('#neeraj_menu ul li a').click(function(){
但是在您提供的 id neeraj 的 html 代码中没有出现
关于javascript - 动态更改html中的分区,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17167024/