禁用文本选择并添加例外 [英] disable text selection and add exceptions

查看:117
本文介绍了禁用文本选择并添加例外的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我对<body>

onmousedown='return false;' onselectstart='return false;'

是否可以通过使用javascript输入textareas和selects来给出例外? 如果是的话,你能告诉我怎么做吗?

is it possible to give the exceptions by using javascript for inputs textareas and selects? and if yes then can u show me how?

推荐答案

实际上,您可以禁用文本选择,而无需繁琐的JavaScript事件处理程序.在这里查看我的答案:如何使用CSS禁用文本选择突出显示?

Actually, you can disable text selection without needing heavy-handed JavaScript event handlers. See my answer here: How to disable text selection highlighting using CSS?

摘要:在IE中使用CSS和unselectable expando.

Summary: use CSS and the unselectable expando in IE.

CSS:

*.unselectable {
   -moz-user-select: -moz-none;
   -khtml-user-select: none;
   -webkit-user-select: none;
   -o-user-select: none;
   user-select: none;
}

HTML:

<div id="foo" unselectable="on" class="unselectable">...</div>

这篇关于禁用文本选择并添加例外的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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