dongtang1997 2017-11-01 10:07
浏览 36

相同的代码不能用于更改选择器类型?

I am using bootstrap navbar that contains some menus option. When i click on any menu, it should display the id and loads the corresponding code.

Below is the code:

$('nav a').on('click', function(){
  alert(this.id);
  window.location.href = "admin-editcp.php";
  //var NavId = this.id;
  //fxnNavClicked(NavId);
});

Its displaying correct id but not loading the new page.

When i change the selector type from nav a to testbutton as

$('#testbutton').on('click', function(){
  alert(this.id);
  window.location.href = "admin-editcp.php";
  //var NavId = this.id;
  //fxnNavClicked(NavId);
});

It works for me.. Still not able to find the cause of such issue or mistake?????

Leads will be appreciated

Below is html code

<div class="collapse navbar-collapse navbar-right">
    <ul class="nav navbar-nav temp-nav">
        <li class="active"><a href="index.php"><i class="fa fa-home fa-lg"></i></a></li>
        <li><a href="" id="INavTheHotel">The Hotel</a></li>
            <li class="dropdown">
                  <a href="" class="dropdown-toggle" >Rooms <b class="caret"></b></a>
                  <ul class="dropdown-menu">
                    <li><a href="" id="INavSemiDeluxe">Semi Deluxe Rooms</a></li>
                    <li><a href="" id="INavDeluxe">Deluxe Rooms</a></li>
                  </ul>
            </li>

        <li><a href="" id="INavAroundus">around us</a></li>
        <li><a href="" id="INavTariff">tariff</a></li>
        <li><a href="" id="INavContact">Contact</a></li>   

    </ul>

</div>


<button type="button btn-white" id="testbutton" class="default" data-dismiss="modal">&times;</button>
  • 写回答

1条回答 默认 最新

  • donglu2523 2017-11-01 10:16
    关注

    Just use preventDefault() for this...

    $('nav a').on('click', function(e){
        e.preventDefault();
        alert(this.id);
        window.location.href = "admin-editcp.php";
    });
    
    评论

报告相同问题?

悬赏问题

  • ¥20 测距传感器数据手册i2c
  • ¥15 RPA正常跑,cmd输入cookies跑不出来
  • ¥15 求帮我调试一下freefem代码
  • ¥15 matlab代码解决,怎么运行
  • ¥15 R语言Rstudio突然无法启动
  • ¥15 关于#matlab#的问题:提取2个图像的变量作为另外一个图像像元的移动量,计算新的位置创建新的图像并提取第二个图像的变量到新的图像
  • ¥15 改算法,照着压缩包里边,参考其他代码封装的格式 写到main函数里
  • ¥15 用windows做服务的同志有吗
  • ¥60 求一个简单的网页(标签-安全|关键词-上传)
  • ¥35 lstm时间序列共享单车预测,loss值优化,参数优化算法