zhangwensheng
发贴: 15
积分: 0
|
于 2006-11-10 09:34
<script language="javascript" type="text/javascript"> function checkLength() { var l = document.form1.txt1.value.length; if(l<3) { return true; } else { return false; } } function IsNumber(KeyCode) { if(((KeyCode>47)&&(KeyCode<58))||(KeyCode==8)||(KeyCode==46)) { return true; } else { return false; } } </script> </head>
<body> <script language="javascript" event="onkeydown" for="document"> if(event.srcElement.name=='txt1') { if(!checkLength()) { document.form1.txt2.focus(); return false; } } if(event.srcElement.name=='txt2') { if(!IsNumber(event.keyCode)) { return false; } } </script> <form name="form1"> <input type="text" name="txt1" onfocus="this.value='';"> <input type="text" name="txt2"> </form>
|