Struts1中的单选框怎么验证不能为空,求大神指导,在线等...

发布网友

我来回答

4个回答

热心网友

这个简单,可以在JSP页面用javascript验证,也可以在相应的action页面在接受到表单参数以后对这个参数进行一次非空判断

热心网友

给你一个JS的例子。
---------------------
<html>
<script>
function fun(){
var obj = document.forms[0].elements["selectRaio"];
if(obj.checked){
alert("checked");
}else{
alert("no checked");
}
}
</script>
<body>
<form>
<input type="radio" value="1" name="selectRaio">
<input type="button" value="check" onclick="fun();">
</form>
</body>
</html>

如果是struts1验证的话,那是validator验证了。属于后面验证。
如果不能进行验证,你看一下配置文件是否正确。

现在不知道你需要的是那一种方式。

struts是一种框架。你的业务处理都要在action中进行
与你用什么验证没有太大关系。

热心网友

这和struts1 2 3 4 5都没有任何关系
你完全可以在提交之前用js验证啊
js验证通过后,使用js去submit表单就ok了

热心网友

if(checkID()){
var retValue = "";
for (var i = 0; i < document.forms(0).selectItem.options.length; i++) {
retValue += document.forms(0).selectItem.options[i].value;
retValue += ",";
}
document.forms(0).retValue.value = retValue.substring(0, retValue.length - 1);
document.forms(0).action.value = "saveInfo";
document.forms(0).submit();
}

声明声明:本网页内容为用户发布,旨在传播知识,不代表本网认同其观点,若有侵权等问题请及时与本网联系,我们将在第一时间删除处理。E-MAIL:11247931@qq.com