onkeypress 事件会在键盘按键被按下并释放一个键时发生。
在本例中,用户无法在输入框中键入数字:
<html><body>
<script type="text/javascript">
function noNumbers(e)
{
var keynum
var keychar
var numcheck
if(window.event) // IE
{
keynum = e.keyCode
}
else if(e.which) // Netscape/Firefox/Opera
{
keynum = e.which
}
keychar = String.fromCharCode(keynum)
numcheck = /\d/
return !numcheck.test(keychar)
}
</script>
<form>
<input type="text" onkeypress="return noNumbers(event)" />
</form>
</html>
<input type="button" name="btn" value="点击101"onclick=" cal(prompt('请输入第一个键盘按键字母:'),prompt('请输入第二个键盘按键字母:')) " />
<script type="text/javascript">
function cal(num01,num02){
/*var num11 = parseInt(num01)
var num22 = parseInt(num02)*/
alert(num01)
alert(num02)
}
</script>