js只能输入数字和小数点的文本框代码
[html] view plaincopyprint? 01.<input type="text" onkeydown="javascript:return isNumber(event,value);"/> <input type="text" onkeydown="javascript:return isNumber(event,value);"/> js部分:
[javascript] view plaincopyprint? 01.<script> 02.isNumber = function (e,s) { 03. var t = 0; 04. //只能输入一个小数点 05. if(s.indexOf(".") != -1){ 06. t = 1; 07. } 08. 09. if(t==1&&((event.keyCode == 190)||(event.keyCode == 110))){ 10. return false; 11. } 12. 13. //IE浏览器 14. if ($.browser.msie) { 15. if ( ((event.keyCode > 47) && (event.keyCode < 58)) || ((event.keyCode > 95) && (event.keyCode < 106)) || 16. (event.keyCode == 8 || (event.keyCode == 190) || (event.keyCode == 110))) { 毕业论文 17. return true; 18. } else { 19. return false; 20. } 21. }else { 22. if ( ((e.which > 47) && (e.which < 58)) || ((e.which > 95) && (e.which < 106)) || 23. (e.which == 8)||(e.which == 110)||(e.which == 190)) { 24. return true; 25. } else { 26. return false; 27. } 28. } 29. return true; 30.} 31.</script>
|