在jQuery中双击禁用文本突出显示 [英] disable text highlighting on double click in jQuery

查看:106
本文介绍了在jQuery中双击禁用文本突出显示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这个jQuery切换。它工作正常。

I have this jQuery toggle. It work fine.

   <ul>
    <li>Go to the store</li>
    <li>Pick up dinner</li>
    <li>Debug crash</li>
    <li>Take a jog</li>
  </ul>

 

        $("li").toggle(
          function () {
            $(this).css({"list-style-type":"disc", "color":"blue"});
          },
          function () {
            $(this).css({"list-style-type":"disc", "color":"red"});
          },
          function () {
            $(this).css({"list-style-type":"", "color":""});
          }
        );

问题是当我快速点击时,它会突出显示其中的文字。
有没有办法阻止文本突出显示?

The problem is when I do fast clicking, it highlighted the text in it. Is there a way to stop the text from being highlighted?

推荐答案

我在iPhone上写字,而离开从桌面上,但是一个快速的谷歌出现在这个页面上:用jQuery禁用文本选择

I'm writing on iPhone, while away from the desk, but a quick Google turned up this page: disable text selection with jQuery.

已编辑以响应死链接评论(来自@Herb Caudill)。虽然原来的链接确实已经死了,但它似乎是由于网站重组(而不是删除)而且文章的新位置可以在这里找到: http://chris-barr.com/index.php/entry/disable_text_selection_with_jquery/

Edited in response to the 'dead link' comment (from @Herb Caudill). While the original link is, indeed, dead, it appears to be due to a site restructuring (rather than removal) and the new location for the article can be found here: http://chris-barr.com/index.php/entry/disable_text_selection_with_jquery/

该文章中提供的代码转载如下:

And the code provided in that article is reproduced below:

$(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'
});

这篇关于在jQuery中双击禁用文本突出显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆