Prevent Highlight of Text Table

后端 未结 7 1953
悲&欢浪女
悲&欢浪女 2020-12-01 01:47

I have a table, and I\'m allowing users to \'select\' multiple rows. This is all handled using jQuery events and some CSS to visually indicate the row is \'selected\'. When

7条回答
  •  青春惊慌失措
    2020-12-01 01:49

    If you want to have control when your users can select or not parts of you site, you can use this little jQuery plugin.

    jQuery.fn.extend({ 
            disableSelection : function() { 
                    return this.each(function() { 
                            this.onselectstart = function() { return false; }; 
                            this.unselectable = "on"; 
                            jQuery(this).css('user-select', 'none'); 
                            jQuery(this).css('-o-user-select', 'none'); 
                            jQuery(this).css('-moz-user-select', 'none'); 
                            jQuery(this).css('-khtml-user-select', 'none'); 
                            jQuery(this).css('-webkit-user-select', 'none'); 
                    }); 
            } 
    }); 
    

    and use it as:

    // disable selection on #theDiv object
    $('#theDiv').disableSelection(); 
    

    Otherwise, you can just use these css attributes inside your css file as:

    #theDiv
     {
        -webkit-user-select: none;
        -khtml-user-select: none;
        -moz-user-select: none;
        -ms-user-select: none;
        user-select: none;
    }
    

提交回复
热议问题