Click Entire Row (preserving middle click and ctrl+click)

后端 未结 10 1186
独厮守ぢ
独厮守ぢ 2020-12-07 20:49

I have an HTML table with a link in the first column. I want to allow the user to click anywhere in the row to activate that link. At the same time, I would like to preser

10条回答
  •  一整个雨季
    2020-12-07 21:33

    You want this:

    $('table#row_link tbody tr').mousedown( function(e){
        if(e.ctrlKey || (!$.browser.msie && e.button == 1) || ($.browser.msie && e.button == 4)){
            //middle mouse button or ctrl+click
        } else {
            //normal left click
        }
    });
    

    This is tested in FF3.0.10, Chrome 1.0 and IE6. I use the mousedown event because neither firefox or IE passes the middle mouse button click to a .click(fn) event.

提交回复
热议问题