我相信我看到过一些网站可以让Firefox(和其他浏览器?)仅选择一个div中的文本,而不跨越其他div。我该如何实现这个功能呢?
基于 this。
<html>
<head>
<title>No Select!</title>
<script>
window.onload = function() {
document.onselectstart = function() {return false;} // ie
document.onmousedown = function() {return false;} // mozilla
}
</script>
</head>
<body>
Select me!
</body>
</html>
顺便说一下,尽量避免这种行为,因为阻止访问者享有基本权利并不酷!如果有人想选择文本,他们会知道如何做,并且没有办法阻止它。