Stop table row toggle upon clicking link

泪湿孤枕 提交于 2020-01-04 09:03:27

问题


What I am trying to do is to stop the toggling when someone clicks on a url link in the table row.

$(document).ready(function () {
    $("#report tr:odd").addClass("odd");
    $("#report tr:not(.odd)").hide();
    $("#report tr:first-child").show();

    $("#report tr.odd").click(function () {
        $(this).next("tr").toggle();
        $(this).find(".arrow").toggleClass("up");
    });
    //$("#report").jExpand();
});

The url link sits right on the same toggling row which in turn when someone clicks the url link, it also toggles the row which I am trying to stop. Any pointers on how to do this?


回答1:


As the anchor is in tr element,whenever click on anchor is called ,the event will be propagated to the parent tr and its click function is also executed.

$('a').click(function(e){
    e.stopPropagation();
});

this stops the event of anchor click to bubble up to the parent




回答2:


I think below might work for you. Not tested though.

add a Javascript function call in your link

$("#ANCHIOR_ID").click(function(event){
    event.stopPropagation();
    // then do your job there that you want to do in on click
  });


来源:https://stackoverflow.com/questions/20699358/stop-table-row-toggle-upon-clicking-link

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!