I am using a syntax like this
if(e.keycode == 17 ....
e.preventDefault()
and works for all keys controls, alts, tabs and etc all but one the space which the keycode is 38 I want to prevent the user from typing whitespaces in a textbox
I am using a syntax like this
if(e.keycode == 17 ....
e.preventDefault()
and works for all keys controls, alts, tabs and etc all but one the space which the keycode is 38 I want to prevent the user from typing whitespaces in a textbox
你可以使用 jquery 来做到这一点。请在这里查看我的样品。 http://jsfiddle.net/SinPride/9P29p/
<input type="text" id="txt_name">
<script>
$('#txt_name').keypress(function( e ) {
if(e.which === 32)
return false;
});
</script>