acpp
V2EX  ›  问与答

v2还有没睡觉的前端么朋友么,来帮下忙

  •  
  •   acpp · Oct 30, 2012 · 3101 views
    This topic created in 4945 days ago, the information mentioned may be changed or developed.
    怎么能用最短的一段代码获取到当前页面的路径

    <div class="show-tabs">
    <a name="brief_tab"></a>
    <ul>
    <li class="selected">商品简介</li>
    <li class="other"><a href="#records_tab">购买记录</a></li>
    <li class="other"><a href="#comment_tab">客户评价 </a><span>()</span></li>
    <li class="other"><a href="#consult_tab">商品咨询 </a><span>()</span></li>
    <li class="other"><a href="#shouhou_tab">售后服务</a></li>
    <li class="other"><a href="#pay_tab">支付方式</a></li>
    </ul>
    </div>

    现在这段代码,#号前,在点击的时候,直接获取到的是首页的路径,我像在#前加段获取当前页面地址的js 然后获取到当前页面地址
    2 replies    1970-01-01 08:00:00 +08:00
    hzlzh
        1
    hzlzh  
    PRO
       Oct 30, 2012
    刚好正要睡,下面这样功能?
    $('a[href^="#"]').each(function(index){
    $(this).attr('href',location.href + $(this).attr('href'));
    });
    acpp
        2
    acpp  
    OP
       Oct 30, 2012
    @hzlzh 谢谢啊,我试试
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   2631 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 38ms · UTC 15:49 · PVG 23:49 · LAX 08:49 · JFK 11:49
    ♥ Do have faith in what you're doing.