Home >Web Front-end >JS Tutorial >Firefox-compatible text boxes can only enter codes with two decimal places_Form special effects

Firefox-compatible text boxes can only enter codes with two decimal places_Form special effects

WBOY
WBOYOriginal
2016-05-16 18:38:381046browse

[Ctrl A select all Note: If you need to introduce external Js, you need to refresh to execute
]<script> function checkNumber(e,txt) { var key = window.event ? e.keyCode : e.which; var keychar = String.fromCharCode(key); var el = document.getElementById('test'); var msg = document.getElementById('msg'); reg = /\d|\./; var result = reg.test(keychar); if(result) { if(e.keyCode==46) result=!(txt.value.split('.').length>1); else result=!(txt.value.split('.').length>1&&txt.value.split('.')[1].length>1); } if(!result) { el.className = "warn"; msg.innerHTML = "只能输入数字"; return false; } else { el.className = ""; msg.innerHTML = ""; return true; } } </script>
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn