日期:2014-05-16  浏览次数:20305 次

常用JS验证(一)

1. js(文本框只允许输入数字)

<form>
????<input type="text" name="money" onkeypress="checkNum(this)">
</form>
<script language="javascript" type="text/javascript">
????function checkNum()
????{
????????if(window.event.keyCode > '9'.charCodeAt(0) ||
???????????window.event.keyCode < '0'.charCodeAt(0))
????????{
????????????window.event.returnValue=false;
????????}
????}
</script>

2.js(ip地址输入)

?

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<meta name="GENERATOR" content="Microsoft FrontPage 4.0">
<meta name="ProgId" content="FrontPage.Editor.Document">
<style>