validate:function(section){
var elements=this.sections.$sections.eq(section).data('elements') //reference elements within this section that should be validated
var validated=true, invalidtext=["Fill the following areas:\n"]
function invalidate(el){
validated=false
invalidtext.push("- "+ (el.id || el.name))
}
for (var i=0; i<elements.length; i++){
if (/(text)/.test(elements[i].type) && elements[i].value==""){ //text and textarea elements
invalidate(elements[i])
}
else if (/(select)/.test(elements[i].type) && (elements[i].selectedIndex==-1 || elements[i].options[elements[i].selectedIndex].text=="")){ //select elements
invalidate(elements[i])
}
else if (elements[i].type==undefined && elements[i].length>0){ //radio and checkbox elements
var onechecked=false
for (var r=0; r<elements[i].length; r++){
if (elements[i][r].checked==true){
onechecked=true
break
}
}
if (!onechecked){
invalidate(elements[i][0])
}
}
}
if (!validated)
alert(invalidtext.join('\n'))
return validated
},
我想向此函数添加一个控件,以检查字段是否可见。我试图将其添加到 if 行但没有用;
elements[i].style.display=="none"
我隐藏表格不输入,这是原因吗?有没有其他方法可以添加这个控件?
编辑 解决方案:elements[i].style.display!=="none"