javascript选中对象

  javascript实现对象选中,选中指定的对象,javascript实现ctrl+all功能,兼容ie,firefox,chrome。

  源代码如下

//el:要选中的对象
function selectText(el) {
    if(  window.getSelection){
     var s=window.getSelection()
     s.selectAllChildren(  el )
    }else{
     var s= document.body.createTextRange ();  
      s.moveToElementText (el);  
      s.select();   
    }
}
selectText(document.body);//实现ctrl+all功能,全选

 

加支付宝好友偷能量挖...


原创文章,转载请注明出处:javascript选中对象

评论(0)Web开发网
阅读(106)喜欢(1)JavaScript/Ajax开发技巧