如何使文本框中輸入的必須是數字?

這個方法也不錯的  
  1.只允許輸入數字(含負數,小數)  
  2.禁止漢字  
  3.允許paste,但不破壞clipboard  
  4.允許drag  
   
  <script>  
  function   check()  
  {  
  entervalue   =   document.form1.mytext.value;  
  if(entervalue!='-')  
  {  
  if(((entervalue-0).toString())=="NaN")  
  {  
  var   entervaluelength   =   entervalue.length;  
  document.form1.mytext.value=entervalue.substring(0,(entervaluelength-1));  
  }  
  }  
  setTimeout("check()",1);  
  }  
  </script>  
  <form   name=form1>  
  <input   name=mytext   οnfοcus=check()>  
  <input   name=mytext2>  
  輸入過程中即時檢查文本框  
  </form> 
發佈了7 篇原創文章 · 獲贊 0 · 訪問量 3萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章