开发者

how to know click event has been fired or not in jquery?

I have the following problem to be solved.

I have few rows of data. When i click one row the color of the row has to be changed and when i click the other row the color of the previous selected row should become normal and the current row should be highlighted with the color. This is done through the following code.

C开发者_StackOverflowheck = function()
{

    $('tr').click(function(){
        $('tr').removeClass("coloradd");
        $(this).addClass("coloradd");

    });

};

But now a complexity is added to the requirements. When i press the shift key and select multiple rows the selected rows should get highlighted. Could anyone help me out with this?


You can test for the shift key like this (I also included a little optimization):

$('tr').click(function(e){
    // Only run if Shift key is not held down
    if(!e.shiftKey) $('tr.coloradd').removeClass("coloradd");

    // Always select the current row
    $(this).addClass("coloradd");
});


Check = function()
{

    $('tr').click(function(e){
       var code = (e.keyCode ? e.keyCode : e.which);
       if(code != SHIFT_KEY_CODE_HERE) { 
         $('tr').removeClass("coloradd");
       }

       $(this).addClass("coloradd");

    });

};
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜