javascript - How to get the dom again after refreshing the page?
怪我咯
怪我咯 2017-05-19 10:14:25
0
4
455

I used include.js. After making the sidebar independent, click on li in the sidebar. li contains a link to other pages.
The problem is:

点击li后 让li上面  >首页>关于我们 中的 关于我们, 点击不同的li改变成相对应的文字.

Code:

HTML:
<p class="current_page clearfix">
<img src="../images/manage_money_arrow.png" alt="" class="fl">
<span class="fl">首页</span>
<i class="fl"><img src="../images/manage_money_gt.png" alt=""></i>
<span class="cur_page">关于我们</span>

</p>
<p class="left_nav fl">

    <ul>
        <li><a href="aboutus.html#0">关于我们<i></i></a></li>
        <li><a href="team.html#1">团队介绍<i></i></a></li>
        <li><a href="honor.html#2">荣誉资质<i></i></a></li>
        <li><a href="law.html#3">法律顾问<i></i></a></li>
        <li><a href="partner.html#4">合作伙伴<i></i></a></li>
        <li><a href="safe.html#5">安全保障<i></i></a></li>
        <li><a href="index.html#6">公司新闻<i></i></a></li>
        <li><a href="recruitment.html#7">招贤纳士<i></i></a></li>
        <li><a href="contactus.html#8">联系我们<i></i></a></li>
        <li class="img">
            <img src="../images/about_left_pic.png" alt="">
        </li>
    </ul>

</p>

JS:
$('.left_nav ul li').on('click', function () {

        var a = $(this).text();
        //alert(a);
        $('.cur_page').html(a);

    })
重点: 由于被独立出来,所以每次点击li的时候,页面都会刷新,文字刚被加上,一刷新就又变回去了.求大神指导! 感谢!
怪我咯
怪我咯

走同样的路,发现不同的人生

reply all(4)
Peter_Zhu

A link has an address. Clicking it will jump to the address.
If you don’t want to jump, give a return false, or change the address to #

左手右手慢动作

After looking at it, you probably want to make breadcrumb navigation. Generally, this kind of breadcrumb navigation directly takes the value of the background, including your li navigation, which should be generated by the background. If written in a backend language, it is probably to obtain the position of the current page and the superior of the current page, and then loop them out. If implemented on the front end. . . Never thought of it before, maybe? I want to go.

漂亮男人

Looking at your code, it’s the same as breadcrumb navigation.

Your a link jumps to a new page.
Is it okay to change the text in the header on the new page?

習慣沉默

For JS click events, it is recommended to use delegation

According to your href characteristics, JS writing is triggered when the page is completed:

var lia;
$('.left_nav ul').find('a').each(function(){
    if(this.hash==location.hash){
        lia=this;
        return false;
    }
});
lia && $(lia).parent().addClass('img');

Handwritten, not verified, just understand the meaning

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template