Trigger a click event on an inner element

前端 未结 14 654
后悔当初
后悔当初 2020-12-29 07:53

A row in a table where each first cell contains a link needs to be clicked and open a url.

14条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-12-29 08:19

    I was able to do it by giving each link a unique ID and then using jQuery to set the click event of that unique ID to redirect the window to the appropriate page.

    Here is my working example: http://jsfiddle.net/MarkKramer/F5aMb/2/

    And here is the code:

    $('#link1').click(function(){
        // do whatever I want here, then redirect
        window.location.href = "detail.aspx?CID=67525";
    });
    $('#link2').click(function(){
        // do whatever I want here, then redirect
        window.location.href = "detail.aspx?CID=17522";
    });
    
    $("table tr").click(function(e) {
        e.stopImmediatePropagation();
        $(this).find("a").trigger('click');
    });
    

提交回复
热议问题