码迷,mamicode.com
首页 > Web开发 > 详细

JS表单验证

时间:2016-05-17 09:52:45      阅读:262      评论:0      收藏:0      [点我收藏+]

标签:

1、js验证radio是否选择

 

<!DOCTYPE >
<html>

<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>无标题文档</title>
<script type="text/javascript" src="js/jquery-2.2.2.min.js">
</script>

<script type="text/javascript">
function checkform(obj) {
for (i = 0; i < obj.oo.length; i++)
if (obj.oo[i].checked == true) {
return true;
} else {
alert("请选择")
return false;
}
}
</script>
</head>

<body>

<form id="form" name="form" method="post" action="" onsubmit="return checkform(this)">
<input type="radio" name="oo" value="radiobutton"/>选项一
<input type="radio" name="oo" value="radiobutton"/>选项二
<input type="submit" name="Submit" value="提交"/>
</form>
</body>

</html>
技术分享


2、长度限制
<script>
function test() {
if (document.a.b.value.length > 5) {
alert("不能超过5个字符!");
document.a.b.focus();
return false;
}
}
</script>
<form name="a" onsubmit="">
<textarea name="b" cols="40" wrap="VIRTUAL" rows="6" onchange="return test()"></textarea>
</form>
技术分享
3、只能是汉字

 

 

JS表单验证

标签:

原文地址:http://www.cnblogs.com/theWayToAce/p/5500321.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!