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

后端 未结 10 1184
独厮守ぢ
独厮守ぢ 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:35

    Here's something that should work: Instead of using window.location, us .click() to emulate a click on the first inside the element. Also, use a conditional to check for CTRL+Click.

    Should look like this:

    $("table#row_link tbody tr").click(function (e) {
        if(e.ctrlKey) { 
            // Run Ctl+Click Code Here
        } else { 
            $(this).children('a').eq(0).click(); 
        }
    }
    

    Hope this helps!

    Dave Romero

提交回复
热议问题