IE,firefox下禁止元素文本被选取的方法

IE下有onselectstart这个方法,通过设置这个方法可以禁止元素文本被选取。而firefox下没有这个方法,但可以通过css或一种变通的办法解决:

  1. if (typeof(element.onselectstart) != "undefined") {       
  2.     // IE下禁止元素被选取       
  3.     element.onselectstart = new Function("return false");       
  4. else {       
  5.     // firefox下禁止元素被选取的变通办法       
  6.     element.onmousedown = new Function("return false");       
  7.     element.onmouseup = new Function("return true");       
  8. }  
或使用CSS:
  1. div {       
  2.     -moz-user-select: none;       
  3. }   
 

本文相关评论|Comments

 

发表该文评论|Send Comment