javascript - 动态更改html中的分区

标签 javascript html css

我做了一个代码,点击不同的链接,具体的部门会分别改变。

第一个文件是: 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/

相关文章:

php - 使用数组选择mysql中的行

html - 使用 flexbox 在 IE11 中布局不正确

javascript - 如何让浏览器等待 Assets 加载?

css - 使用回形针附件作为 activeadmin site_title_image

javascript - 像研究 Jquery 一样的彩蛋

javascript - IE 10 和 IE 11 的解析日期问题

html - :focus styling on custom radio input

javascript - 当有最小宽度时,如何使元素中心(水平)固定位置?

javascript - 使用当前日期、月份和年份填充下拉列表

Javascript 撇号解码