我是JQuery Validation插件的新手。
我使用过JQuery Validation插件,无法像在JavaScript中那样使用验证。
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js" ></script>
<script type="text/javascript" src="http://jzaefferer.github.com/jquery-validation/jquery.validate.js" ></script>
<script type="text/javascript">
$().ready(function() {
$.validator.addMethod("mondayincheck", function(value,element) {
if($('#hoomonon').val() == '' && $('#hoomonout').val() != '') {
return true;
} else {
return false;
}
},"<br>* Choose Monday Out Time"
);
/*$.validator.addMethod("mondayoutcheck", function(value, element) {
return ($('#hoomonon').val() == '' && $('#hoomonout').val() != '')
}, "<br>* Choose Monday Out Time"
);*/
/*$("#signupform").validate({
rules: {
telephone: {
required: function(element) {
if ($("#mobile").val().length > 0) {
return false;
}
else {
return true;
}
}
},
mobile: {
required: function(element) {
if ($("#telephone").val().length > 0) {
return false;
}
else {
return true;
}
}
}
}
});*/
// validate signup form on keyup and submit
$("#postadd").validate({
rules: {
hoomonon: {
required : function(element) {
//alert($('#hoomonon').val() == '' && $('#hoomonout').val() == '' && $('#hoomonoff:checked') == false);
if(($('#hoomonon').val() == '' && $('#hoomonout').val() == '') || ($('#hoomonoff:checked') == false)) {
return true;
}
},
mondayincheck : true
},
/*hoomonout: {
required : function(element) {
if($('#hoomonon').val() != '' && $('#hoomonout').val() == '') {
return true;
}
}
},*/
hootueon: {
required:true
},
hootueout: {
required:true
},
hoowedon: {
required:true
},
hoowedout: {
required:true
},
hoothuon: {
required:true
},
hoothuout: {
required:true
},
hoofrion: {
required:true
},
hoofriout: {
required:true
},
hoosaton: {
required:true
},
hoosatout: {
required:true
},
hoosunon: {
required:true
},
hoosunout: {
required:true
}
},
messages: {
hoomonon: {
required : "<br>* Choose Monday Timing or Closed"
},
/*hoomonout: {
required : "<br>* Choose Monday Out Time"
},*/
hootueon: {
required : "<br>* Required Field"
},
hootueout: {
required : "<br>* Required Field"
},
hoowedon: {
required : "<br>* Required Field"
},
hoowedout: {
required : "<br>* Required Field"
},
hoothuon: {
required : "<br>* Required Field"
},
hoothuout: {
required : "<br>* Required Field"
},
hoofrion: {
required : "<br>* Required Field"
},
hoofriout: {
required : "<br>* Required Field"
},
hoosaton: {
required : "<br>* Required Field"
},
hoosatout: {
required : "<br>* Required Field"
},
hoosunon: {
required : "<br>* Required Field"
},
hoosunout: {
required : "<br>* Required Field"
}
}
});
});
</script>
以下是我使用JQuery Validation插件验证的表单,但我不知道如何验证以下表单。我已经尝试了很多选择但是他们没有成功
<form id="postadd" name="postadd" method="post" action="" enctype='multipart/form-data' >
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="9%" height="30" align="left" valign="middle">Mon : </td>
<td width="30%" align="left" valign="middle"><select class="timinput" name="hoomonon" id="hoomonon">
<option value=''>--------Time--------</option>
<option value='1:00 AM'>1:00 AM</option>
<option value='1:30 AM'>1:30 AM</option>
<option value='2:00 AM'>2:00 AM</option>
<option value='2:30 AM'>2:30 AM</option>
</select>
- </td>
<td width="29%" align="left" valign="middle"><select class="timinput" name="hoomonout" id="hoomonout">
<option value=''>--------Time--------</option>
<option value='1:00 AM'>1:00 AM</option>
<option value='1:30 AM'>1:30 AM</option>
<option value='2:00 AM'>2:00 AM</option>
<option value='2:30 AM'>2:30 AM</option>
</select></td>
<td width="32%" height="40" align="left" valign="middle" class="txt"><label>
<input type="checkbox" name="hoomonoff" id="hoomonoff" value="Closed" />
</label>
Closed</td>
</tr>
<tr>
<td height="30" align="left" valign="middle">Tue : </td>
<td align="left" valign="middle"><select class="timinput" name="hootueon" id="hootueon">
<option value=''>--------Time--------</option>
<option value='1:00 AM'>1:00 AM</option>
<option value='1:30 AM'>1:30 AM</option>
<option value='2:00 AM'>2:00 AM</option>
<option value='2:30 AM'>2:30 AM</option> </select>
- </td>
<td align="left" valign="middle"><select class="timinput" name="hootueout" id="hootueout">
<option value=''>--------Time--------</option>
<option value='1:00 AM'>1:00 AM</option>
<option value='1:30 AM'>1:30 AM</option>
<option value='2:00 AM'>2:00 AM</option>
<option value='2:30 AM'>2:30 AM</option> </select></td>
<td height="40" align="left" valign="middle" class="txt"><input type="checkbox" name="hootueoff" id="hootueoff" value="Closed" />
Closed </td>
</tr>
<tr>
<td height="30" align="left" valign="middle">Wed : </td>
<td align="left" valign="middle"><select class="timinput" name="hoowedon" id="hoowedon">
<option value=''>--------Time--------</option>
<option value='1:00 AM'>1:00 AM</option>
<option value='1:30 AM'>1:30 AM</option>
<option value='2:00 AM'>2:00 AM</option>
<option value='2:30 AM'>2:30 AM</option> </select></td>
<td align="left" valign="middle"><select class="timinput" name="hoowedout" id="hoowedout">
<option value=''>--------Time--------</option>
<option value='1:00 AM'>1:00 AM</option>
<option value='1:30 AM'>1:30 AM</option>
<option value='2:00 AM'>2:00 AM</option>
<option value='2:30 AM'>2:30 AM</option> </select></td>
<td height="40" align="left" valign="middle" class="txt"><input type="checkbox" name="hoowedoff" id="hoowedoff" value="Closed" />
Closed </td>
</tr>
<tr>
<td height="30" align="left" valign="middle">Thu : </td>
<td align="left" valign="middle"><select class="timinput" name="hoothuon" id="hoothuon">
<option value=''>--------Time--------</option>
<option value='1:00 AM'>1:00 AM</option>
<option value='1:30 AM'>1:30 AM</option>
<option value='2:00 AM'>2:00 AM</option>
<option value='2:30 AM'>2:30 AM</option> </select></td>
<td align="left" valign="middle"><select class="timinput" name="hoothuout" id="hoothuout">
<option value=''>--------Time--------</option>
<option value='1:00 AM'>1:00 AM</option>
<option value='1:30 AM'>1:30 AM</option>
<option value='2:00 AM'>2:00 AM</option>
<option value='2:30 AM'>2:30 AM</option> </select></td>
<td height="40" align="left" valign="middle" class="txt"><input type="checkbox" name="hoothuoff" id="hoothuoff" value="Closed" />
Closed</td>
</tr>
<tr>
<td height="30" align="left" valign="middle">Fri : </td>
<td align="left" valign="middle"><select class="timinput" name="hoofrion" id="hoofrion">
<option value=''>--------Time--------</option>
<option value='1:00 AM'>1:00 AM</option>
<option value='1:30 AM'>1:30 AM</option>
<option value='2:00 AM'>2:00 AM</option>
<option value='2:30 AM'>2:30 AM</option> </select></td>
<td align="left" valign="middle"><select class="timinput" name="hoofriout" id="hoofriout">
<option value=''>--------Time--------</option>
<option value='1:00 AM'>1:00 AM</option>
<option value='1:30 AM'>1:30 AM</option>
<option value='2:00 AM'>2:00 AM</option>
<option value='2:30 AM'>2:30 AM</option> </select></td>
<td height="40" align="left" valign="middle" class="txt"><input type="checkbox" name="hoofrioff" id="hoofrioff" value="Closed" />
Closed </td>
</tr>
<tr>
<td height="30" align="left" valign="middle">Sat : </td>
<td align="left" valign="middle"><select class="timinput" name="hoosaton" id="hoosaton">
<option value=''>--------Time--------</option>
<option value='1:00 AM'>1:00 AM</option>
<option value='1:30 AM'>1:30 AM</option>
<option value='2:00 AM'>2:00 AM</option>
<option value='2:30 AM'>2:30 AM</option> </select></td>
<td align="left" valign="middle"><select class="timinput" name="hoosatout" id="hoosatout">
<option value=''>--------Time--------</option>
<option value='1:00 AM'>1:00 AM</option>
<option value='1:30 AM'>1:30 AM</option>
<option value='2:00 AM'>2:00 AM</option>
<option value='2:30 AM'>2:30 AM</option> </select></td>
<td height="40" align="left" valign="middle" class="txt"><input type="checkbox" name="hoosatoff" id="hoosatoff" value="Closed" />
Closed </td>
</tr>
<tr>
<td height="30" align="left" valign="middle">Sun : </td>
<td align="left" valign="middle"><select class="timinput" name="hoosunon" id="hoosunon">
<option value=''>--------Time--------</option>
<option value='1:00 AM'>1:00 AM</option>
<option value='1:30 AM'>1:30 AM</option>
<option value='2:00 AM'>2:00 AM</option>
<option value='2:30 AM'>2:30 AM</option> </select></td>
<td align="left" valign="middle"><select class="timinput" name="hoosunout" id="hoosunout">
<option value=''>--------Time--------</option>
<option value='1:00 AM'>1:00 AM</option>
<option value='1:30 AM'>1:30 AM</option>
<option value='2:00 AM'>2:00 AM</option>
<option value='2:30 AM'>2:30 AM</option> </select></td>
<td height="40" align="left" valign="middle" class="txt"><input type="checkbox" name="hoosunoff" id="hoosunoff" value="Closed" />
Closed</td>
</tr>
</table>
</form>
I am using Jquery Validation plugin in this php page for above form,
I want to validate like this javascript using jquery validation plugin
if(hoomononval == '' && hoomonoutval == '' && document.postadd.hoomonoff.checked==false) {
alert('Please Choose Monday Timing or Closed');
hoomonon.focus();
return false;
}
if(hoomononval != '') {
if(hoomonoutval == '') {
alert('Please Choose Monday Out Time');
hoomonout.focus();
return false;
} else if(hoomononval == hoomonoutval) {
alert('Please Choose different Monday In & Out Time');
hoomonon.focus();
return false;
}
}
if(hoomonoutval != '') {
if(hoomononval == '') {
alert('Please Choose Monday In Time');
hoomonon.focus();
return false;
}
else if(hoomononval == hoomonoutval) {
alert('Please Choose different Monday In & Out Time');
hoomonon.focus();
return false;
}
}
if(hoomononval !='' && hoomonoutval !='') {
var g = 0;
if (document.postadd.hoomonoff.checked==true)
{
//alert('good');
g++;
}
if(g == 1) {
alert("Don't Choose timing if you choose Closed & Viceversa");
hoomonoff.focus();
return false;
}
}
if(hootueonval == '' && hootueoutval == '' && document.postadd.hootueoff.checked==false) {
alert('Please Choose Tuesday Timing or Closed');
hootueon.focus();
return false;
}
if(hootueonval != '') {
if(hootueoutval == '') {
alert('Please Choose Tuesday Out Time');
hootueout.focus();
return false;
} else if(hootueonval == hoowedoutval) {
alert('Please Choose different Tuesday In & Out Time');
hootueon.focus();
return false;
}
}
if(hootueoutval != '') {
if(hootueonval == '') {
alert('Please Choose Tuesday In Time');
hootueon.focus();
return false;
}
else if(hootueonval == hootueoutval) {
alert('Please Choose different Tuesday In & Out Time');
hootueon.focus();
return false;
}
}
if(hootueonval !='' && hootueoutval !='') {
var g = 0;
if (document.postadd.hootueoff.checked==true)
{
//alert('good');
g++;
}
if(g == 1) {
alert("Don't Choose timing if you choose Closed & Viceversa");
hootueoff.focus();
return false;
}
}
if(hoowedonval == '' && hoowedoutval == '' && document.postadd.hoowedoff.checked==false) {
alert('Please Choose Wednesday Timing or Closed');
hoowedon.focus();
return false;
}
if(hoowedonval != '') {
if(hoowedoutval == '') {
alert('Please Choose Wednesday Out Time');
hoowedout.focus();
return false;
} else if(hoowedonval == hoowedoutval) {
alert('Please Choose different Wednesday In & Out Time');
hoowedon.focus();
return false;
}
}
if(hoowedoutval != '') {
if(hoowedonval == '') {
alert('Please Choose Wednesday In Time');
hoowedon.focus();
return false;
}
else if(hoowedonval == hoowedoutval) {
alert('Please Choose different Wednesday In & Out Time');
hoowedon.focus();
return false;
}
}
if(hoowedonval !='' && hoowedoutval !='') {
var g = 0;
if (document.postadd.hoowedoff.checked==true)
{
//alert('good');
g++;
}
if(g == 1) {
alert("Don't Choose timing if you choose Closed & Viceversa");
hoowedoff.focus();
return false;
}
}
if(hoothuonval == '' && hoothuoutval == '' && document.postadd.hoothuoff.checked==false) {
alert('Please Choose Thursday Timing or Closed');
hoothuon.focus();
return false;
}
if(hoothuonval != '') {
if(hoothuoutval == '') {
alert('Please Choose Thursday Out Time');
hoothuout.focus();
return false;
} else if(hoothuonval == hoothuoutval) {
alert('Please Choose different Thursday In & Out Time');
hoothuon.focus();
return false;
}
}
if(hoothuoutval != '') {
if(hoothuonval == '') {
alert('Please Choose Thursday In Time');
hoothuon.focus();
return false;
}
else if(hoothuonval == hoothuoutval) {
alert('Please Choose different Thursday In & Out Time');
hoothuon.focus();
return false;
}
}
if(hoothuonval !='' && hoothuoutval !='') {
var g = 0;
if (document.postadd.hoothuoff.checked==true)
{
//alert('good');
g++;
}
if(g == 1) {
alert("Don't Choose timing if you choose Closed & Viceversa");
hoothuoff.focus();
return false;
}
}
if(hoofrionval == '' && hoofrioutval == '' && document.postadd.hoofrioff.checked==false) {
alert('Please Choose Friday Timing or Closed');
hoofrion.focus();
return false;
}
if(hoofrionval != '') {
if(hoofrioutval == '') {
alert('Please Choose Friday Out Time');
hoofriout.focus();
return false;
} else if(hoofrionval == hoofrioutval) {
alert('Please Choose different Friday In & Out Time');
hoofrion.focus();
return false;
}
}
if(hoofrioutval != '') {
if(hoofrionval == '') {
alert('Please Choose Friday In Time');
hoofrion.focus();
return false;
}
else if(hoofrionval == hoofrioutval) {
alert('Please Choose different Friday In & Out Time');
hoofrion.focus();
return false;
}
}
if(hoofrionval !='' && hoofrioutval !='') {
var g = 0;
if (document.postadd.hoofrioff.checked==true)
{
//alert('good');
g++;
}
if(g == 1) {
alert("Don't Choose timing if you choose Closed & Viceversa");
hoofrioff.focus();
return false;
}
}
if(hoosatonval == '' && hoosatoutval == '' && document.postadd.hoosatoff.checked==false) {
alert('Please Choose Wednesday Timing or Closed');
hoosaton.focus();
return false;
}
if(hoosatonval != '') {
if(hoosatoutval == '') {
alert('Please Choose Saturday Out Time');
hoosatout.focus();
return false;
} else if(hoosatonval == hoosatoutval) {
alert('Please Choose different Saturday In & Out Time');
hoosaton.focus();
return false;
}
}
if(hoosatoutval != '') {
if(hoosatonval == '') {
alert('Please Choose Saturday In Time');
hoosaton.focus();
return false;
}
else if(hoosatonval == hoosatoutval) {
alert('Please Choose different Saturday In & Out Time');
hoosaton.focus();
return false;
}
}
if(hoosatonval !='' && hoosatoutval !='') {
var g = 0;
if (document.postadd.hoosatoff.checked==true)
{
//alert('good');
g++;
}
if(g == 1) {
alert("Don't Choose timing if you choose Closed & Viceversa");
hoosatoff.focus();
return false;
}
}
if(hoosunonval == '' && hoosunoutval == '' && document.postadd.hoosunoff.checked==false) {
alert('Please Choose Sunday Timing or Closed');
hoosunon.focus();
return false;
}
if(hoosunonval != '') {
if(hoosunoutval == '') {
alert('Please Choose Sunday Out Time');
hoosunout.focus();
return false;
}
else if(hoosunonval == hoosunoutval) {
alert('Please Choose different Sunday In & Out Time');
hoosunon.focus();
return false;
}
}
if(hoosunoutval != '') {
if(hoosunonval == '') {
alert('Please Choose Sunday In Time');
hoosunon.focus();
return false;
}
else if(hoosunonval == hoosunoutval) {
alert('Please Choose different Sunday In & Out Time');
hoosunon.focus();
return false;
}
}
if(hoosunonval !='' && hoosunoutval !='') {
var g = 0;
if (document.postadd.hoosunoff.checked==true)
{
//alert('good');
g++;
}
if(g == 1) {
alert("Don't Choose timing if you choose Closed & Viceversa");
hoosunoff.focus();
return false;
}
}
if(document.postadd.hoomonoff.checked==true && document.postadd.hootueoff.checked==true && document.postadd.hoowedoff.checked==true && document.postadd.hoothuoff.checked==true && document.postadd.hoofrioff.checked==true && document.postadd.hoosatoff.checked==true && document.postadd.hoosunoff.checked==true) {
alert("All Days Can't Be Closed");
hoomonon.focus();
return false;
}