Newbie_小白
没有都对的别人,也没有全错的自己,至少要有自己的坚持,无关他人、无关外物!

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、验证邮箱格式
<script type="text/javascript">
function isEmail(strEmail) {
if (strEmail.search(/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/) != -1)
return true;
else
alert("请输入正确的邮箱地址!");
}
</script>
<input type=text onblur=isEmail(this.value)>





 

 

posted on 2016-05-17 09:28  Newbie_小白  阅读(165)  评论(0)    收藏  举报