我可以使用@Tomalak为MY QUESTION提供的解决方案,您能否帮我解决它,因为它在萤火虫中给我一个错误,因为:frm.creatorusers未定义
[中断此错误] var rdo =(frm.creatorusers.length> ... rm.creatorusers:frm.creatorusers;
我将代码用于验证单选按钮,如下所示:
function valDistribution(frm) {
var mycreator = -1;
var rdo = (frm.creatorusers.length > 0) ? frm.creatorusers : frm.creatorusers;
for (var i=0; i<rdo.length; i++) {
if (rdo[i].checked) {
mycreator = 1;
//return true;
}
}
if(mycreator == -1){
alert("You must select a Creator User!");
return false;
}
}
最佳答案
这是使用@Tomalak给出但未正确复制的代码的方法
function valDistribution(frm) { // frm needs to be passed here
var myCreator=false;
// create an array if not already an array
var rdo = (frm.creatorusers.length > 0) ? frm.creatorusers : [frm.creatorusers];
for (var i=0; i<rdo.length; i++) {
if (rdo[i].checked) {
myCreator=true;
break; // no need to stay here
}
if (!myCreator){
alert("You must select a Creator User!");
return false;
}
return true; // allow submission
}
假设onsubmit看起来完全像这样:
<form onsubmit="return valDistribution(this)">
收音机的名称如下:
<input type="radio" name="creatorusers" ...>