zoukankan
html css js c++ java
JavaScript验证页面上动态生成的Radio
<
script type
=
"
text/javascript
"
>
//
Form提交前执行验证
document.forms[
0
].onsubmit
=
function
()
{
//
获得DIV(ID:div_form_content_show)中所有的<Input>对像
var
inputs
=
document.getElementById(
"
div_form_content_show
"
).getElementsByTagName(
"
input
"
);
//
获得DIV(ID:div_form_content_show)中所有的<Textarea>对像
var
textareas
=
document.getElementById(
"
div_form_content_show
"
).getElementsByTagName(
"
textarea
"
);
var
radioname;
var
arrRadio
=
new
Array();
for
(
var
i
=
0
;i
<
inputs.length;i
++
)
{
//
验证text
if
(inputs[i].type
==
"
text
"
)
{
if
(inputs[i].value
==
""
)
{
alert(
"
信息没有填写完整!
"
);
//
inputs[i].style.backgroundColor="red";
inputs[i].focus();
return
false
;
}
}
//
获得页面上所有的radio
else
if
(inputs[i].type
==
"
radio
"
)
{
//
这里将所有的radio根据name分组,便于之后按组判断是否选中(一组选中一个即可)
if
(radioname
!=
inputs[i].name)
{
arrRadio.push(inputs[i].name);
radioname
=
inputs[i].name
}
}
}
//
验证textarea
for
(
var
i
=
0
;i
<
textareas.length;i
++
)
{
if
(textareas[i].value
==
""
)
{
alert(
"
信息没有填写完整!
"
);
//
textareas[i].style.backgroundColor="red";
textareas[i].focus();
return
false
;
}
}
//
按name分组验证radio
for
(
var
i
=
0
;i
<
arrRadio.length;i
++
)
{
var
bRadio
=
false
;
for
(
var
j
=
0
;j
<
document.getElementsByName(arrRadio[i]).length;j
++
)
{
if
(document.getElementsByName(arrRadio[i]).item(j).checked
==
true
)
{
bRadio
=
true
;
continue
;
}
}
if
(
!
bRadio)
{
alert(
"
一些应该选择的项没有被选择!
"
);
return
false
;
}
}
return
true
;
}
<
/
script>
查看全文
相关阅读:
html图片链接不显示图片
Mybatis总结
IllegalArgumentException: Could not resolve resource location pattern [classpath .xml]: class path resource cannot be resolved to URL because it does not exist
java.lang.ClassNotFoundException: com.radiadesign.catalina.session.RedisSessionHandlerValve
sqlserver2008客户端设置主键自增
判断手机还是电脑访问
SSM与jsp传递实体类
ssm打印sql语句
SqlSession 同步为注册,因为同步未激活
for循环取出每个i的值
原文地址:https://www.cnblogs.com/tangself/p/1613778.html
最新文章
一款纯html5实现的人跑步动画
一款基于css3非常实用的鼠标悬停特效
一款基于jquery的手风琴图片展示效果
[Leetcode] Minimum Path Sum
[Leetcode] Unique Paths
[Leetcode] Unique Paths II
[Leetcode] Path Sum II
[Leetcode] Path Sum
[Leetcode] Multiply Strings
[Leetcode] Longest Substring Without Repeating Characters
热门文章
[Leetcode] Permutations II
[Leetcode] Permutations
[Leetcode] Next Permutation
数据结构的简单理解
jQuery总结
javaWeb后端学习记录2018
每月IT摘录201805
Spring依赖注入:注解注入
Failed to execute goal org.mybatis.generator:mybatis-generator-maven-plugin:generate (default-cli) on project : <properties> resource does not exist
Git常用命令
Copyright © 2011-2022 走看看