最近的工作中,接触JS的比较多,碰到个文本框不能拖动选择的问题
发现原来是增加了一个函数
document.onselectstart = function(event) {return false};
那么页面上的所有的选择事件将失效。
譬如我们可以指定哪些是不能选定的
document.onselectstart= function(event){return test()};
function test(){
var the = event.srcElement ;
if( !( ( the.tagName== "INPUT" && the.type.toLowerCase() == "text" ) || the.tagName== "TEXTAREA" ) )
{
return false;
}
return true ;
}
发现原来是增加了一个函数
document.onselectstart = function(event) {return false};
那么页面上的所有的选择事件将失效。
譬如我们可以指定哪些是不能选定的
document.onselectstart= function(event){return test()};
function test(){
var the = event.srcElement ;
if( !( ( the.tagName== "INPUT" && the.type.toLowerCase() == "text" ) || the.tagName== "TEXTAREA" ) )
{
return false;
}
return true ;
}
本文介绍了一种通过JavaScript实现网页元素不可选中的方法,使用document.onselectstart事件阻止默认的选择行为,并提供了如何精确控制哪些元素可以被选中的示例代码。
7805

被折叠的 条评论
为什么被折叠?



