12

私のWebアプリでは、ユーザーが同じボタンを何度もクリックして、メッセージやものをスキップして、</a>が選択されることがあります。

Javascript(jQuery)を使用してこれを防ぐにはどうすればよいですか

4

2 に答える 2

30

これにはスクリプトは必要ありません。css は次のとおりです。

-webkit-touch-callout: none;
-webkit-user-select: none;
-khtml-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;
于 2011-06-17T07:11:40.207 に答える
2

この解決策は私のために働いた:http: //chris-barr.com/entry/disable_text_selection_with_jquery/

$(function(){
    $.extend($.fn.disableTextSelect = function() {
        return this.each(function(){
            if($.browser.mozilla){//Firefox
                $(this).css('MozUserSelect','none');
            }else if($.browser.msie){//IE
                $(this).bind('selectstart',function(){return false;});
            }else{//Opera, etc.
                $(this).mousedown(function(){return false;});
            }
        });
    });
    $('.noSelect').disableTextSelect();//No text selection on elements with a class of 'noSelect'
});
于 2010-08-12T16:37:51.277 に答える