该脚本主要按我的意愿运行:未选中单选复选框时发出警报。但是,如果选择了所有按钮,我需要它提交的表单......这就是我挂断电话的地方。现在,如果选择了所有字段和按钮,那么我仍然会收到带有 var alertMsg 的警报。有任何想法吗?
function submitform() {
var sizeChoice = ""
var size = document.store.on1.length
var fontChoice = ""
var len = document.store.on2.length
var materialChoice = ""
var material = document.store.on3.length
var treatmentChoice = ""
var treatment = document.store.on4.length
var a = document.forms["store"]["item_name"].value;
var alertMsg = "Please Choose a:"
for(i = 0; i < size; i++) {
if(document.store.on1[i].checked) {
sizeChoice = document.store.on1[i].value
}
}
for(i = 0; i < len; i++) {
if(document.store.on2[i].checked) {
fontChoice = document.store.on2[i].value
}
}
for(i = 0; i < material; i++) {
if(document.store.on3[i].checked) {
materialChoice = document.store.on3[i].value
}
}
for(i = 0; i < treatment; i++) {
if(document.store.on4[i].checked) {
treatmentChoice = document.store.on4[i].value
}
}
if(a == null || a == "") alertMsg += "\n" + "Name" + "\n";
if(sizeChoice == "") {
alertMsg += "Size" + "\n"
}
if(fontChoice == "") {
alertMsg += "Font" + "\n"
}
if(materialChoice == "") {
alertMsg += "Material" + "\n"
}
if(treatmentChoice == "") {
alertMsg += "Treatment" + "\n"
} {
alert(alertMsg)
};
return false;
document.forms["form"].submit();
};