我使用jquery系统来验证html表单中的输入。在电子邮件字段中,我想显示表示2条错误消息的validate [required]或custom [email](但不是两者)。 我不是很熟悉Javascript,但这是我的尝试
<form id="formID1" action="report-problem.asp" name="varsForm1" method="post">
<script language="Javascript">...
function IsEmpty(){
var class = "";
if(document.forms['formID1'].email1.value == "")
{
class='validate[required]';
}
else
{
class= 'validate[custom[email]]';
}
return class;
}
</script>
<td>Email Address</td>
<td class="input" width="302"><input name="email1" type="text" id="email1" class="IsEmpty();" value="" /></td>....
<input name="" id="submitbtn" type="submit" value="Send" />
答案 0 :(得分:0)
if(document.forms['formID1'].email1.value == "")
{
$("#email1").removeClass('validate[custom[email]]');
class='validate[required]';
}
else
{
$("#email1").removeClass('validate[required]');
class= 'validate[custom[email]]';
}
return class;
在电子邮件字段中添加新错误类时,应删除上一课程。它应该工作:))