开发者

jQuery double click, but don't select the content

I'm using jquery's dbclick() function in order to toggle highlight of the table raw. The problem I'm facing is that whenever I double click the co开发者_开发知识库ntent of the cell is also selected. Is there an easy way to prevent content selection?

My code:

if ($('.tbl_repeat').length > 0) {
    $('.tbl_repeat tr').dblclick(function() {
        $(this).toggleClass('tr_active');
    });
}

Perhaps I didn't make myself clear - I don't want to disable selecting all together - only when the double click occurs - apart from this event everything else should be selectable as usual.


You can try to deny selection via css on element what you doubleclick

.unselectable {
   -moz-user-select     : none;
   -khtml-user-select   : none;
   -webkit-user-select  : none;
   -o-user-select       : none;
   user-select          : none;
}


Place the below coding between here (between Head Tags)

<style>
        .unselectable {
            -webkit-user-select: none;
            -moz-user-select: none;
            -ms-user-select: none;
            -o-user-select: none;
            user-select: none;   
        }
    </style>

Put this in between here (between Body Tags)

<p class="unselectable"> your unselectable text here </p>

Just like this..

<!DOCTYPE HTML>
<html lang="en-US">
<head>
    <meta charset="UTF-8">
    <title></title>
    <style>
        .unselectable {
            -webkit-user-select: none;
            -moz-user-select: none;
            -ms-user-select: none;
            -o-user-select: none;
            user-select: none;   
        }
    </style>
</head>
<body>
    <p class="unselectable">
    <span> your unselectable text here </span><br>
    <a href="#" onclick="return false;"> your unselectable link here </a></p>
</body>
</html>​
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜