我正在写一个简单的" Flash Cards"在没有重新加载的情况下在网页上显示/消失的应用程序。我正在寻找一种通过jQuery禁用/启用选择的方法,以便在重复单击按钮时不会突出显示应用程序的区域。有没有办法使用jQuery将背景设置为透明与::选择?我正在寻找类似的东西:
$("*::selection").css("background","transparent");
而不是在css文件中写这个:
*::selection {background:transparent;}
PS我也有兴趣选择特定元素,而不是使用*,如果可能的话。
答案 0 :(得分:2)
<强> HTML:强>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit...</p>
<button>Selection toggle</button>
<强> CSS:强>
.selection *::selection {background:transparent;}
<强> jQuery的:强>
$('button').click(function() {
$('html').toggleClass('selection');
if (document.selection) { // IE
document.selection.empty();
} else if (window.getSelection) { // OTHERS
window.getSelection().removeAllRanges();
}
});