我的页面的一部分需要双击,这具有不良影响,有时用户无意中突出显示页面上的某些文本。停止HTML文本被突出显示
这真的只是乱糟糟的,但有没有一种简单的方法来阻止这种情况发生,除了通过使用图像而不是文本?
谢谢
我的页面的一部分需要双击,这具有不良影响,有时用户无意中突出显示页面上的某些文本。停止HTML文本被突出显示
这真的只是乱糟糟的,但有没有一种简单的方法来阻止这种情况发生,除了通过使用图像而不是文本?
谢谢
这里是CSS禁用文本选择。 How to disable text selection highlighting using CSS?
-webkit-touch-callout: none;
-webkit-user-select: none;
-khtml-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
-o-user-select: none;
user-select: none;
由于@arunes建议,你可以用CSS大多数浏览器做到这一点。不过,我读过,这不适用于IE 6-8(至少)。因此,对于这一点,你可能需要的东西,如:
document.getElementById("divDoubleClick").onselectstart = function() { return false; };
这对我的作品
的建议把CSS样式
body, div
{
-webkit-touch-callout: none;
-webkit-user-select: none;
-khtml-user-select: none;
-moz-user-select: -moz-none;
-ms-user-select: none;
-o-user-select: none;
user-select: none;
}
还添加这些允许的表单字段中选择
input, textarea, .userselecton
{
-webkit-touch-callout: text;
-webkit-user-select: text;
-khtml-user-select: text;
-moz-user-select: text;
-ms-user-select: text;
-o-user-select: text;
user-select: text;
}
请注意,-moz-none所需或重新启用输入不起作用。
IE浏览器我添加
<script type="text/javascript">
window.addEvent("domready", function()
{
document.addEvent("selectstart", function(e)
{
if ((e.target.tagName == "INPUT") ||
(e.target.tagName == "TEXTAREA") ||
(e.target.hasClass("userselecton")))
{
return true;
}
return false;
});
});
</script>
这不仅防止背景的文本选择,但允许在inputfields选择和和元素,你穿上userseleton类。
感谢有用的信息! – CompanyDroneFromSector7G 2016-03-07 09:26:36
对我来说够好!谢谢:) – CompanyDroneFromSector7G 2012-03-08 15:41:18
为什么添加-webkit-touch-callout:none;? – 2016-05-03 11:13:34