问题描述
我有这个 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 上写作,当时我不在办公桌前,但 Google 很快打开了这个页面:使用 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 中双击禁用文本突出显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!