0
我想在提交之前驗證一個表單。驗證工作正常,但表單沒有提交。我沒有足夠的關於jQuery的知識,但我懷疑這是使用快捷方式$和jQuery在一起,我是對的或者問題在別處?
CODE:
<script type="text/javascript">
$('p select[name=country]').change(function(){
if ($('p select[name=country]').val() =='Au')
{
$('#seldivi').show();
}
else
{
$('#seldivi').hide();
}
});
$(function(){
$("a.mytrigger").click(function(e){
var index = $(this).attr("href").substr(5);
$('#navigation li:nth-child('+parseInt(index)+') a').click();
e.preventDefault();
});
});
//when i remove the following segment of codes the form submitted as usual but when this portion exists the form is not submitted
jQuery(function(){
jQuery("#ValidField").validate({
expression: "if (VAL) return true; else return false;",
message: "Please enter the Required field"
});
jQuery("#ValidNumber").validate({
expression: "if (!isNaN(VAL) && VAL) return true; else return false;",
message: "Please enter a valid number"
});
jQuery("#ValidInteger").validate({
expression: "if (VAL.match(/^[0-9]*$/) && VAL) return true; else return false;",
message: "Please enter a valid integer"
});
jQuery("#ValidDate").validate({
expression: "if (!isValidDate(parseInt(VAL.split('-')[2]), parseInt(VAL.split('-')[0]), parseInt(VAL.split('-')[1]))) return false; else return true;",
message: "Please enter a valid Date"
});
jQuery("#ValidEmail").validate({
expression: "if (VAL.match(/^[^\\W][a-zA-Z0-9\\_\\-\\.]+([a-zA-Z0-9\\_\\-\\.]+)*\\@[a-zA-Z0-9_]+(\\.[a-zA-Z0-9_]+)*\\.[a-zA-Z]{2,4}$/)) return true; else return false;",
message: "Please enter a valid Email ID"
});
jQuery("#ValidPassword").validate({
expression: "if (VAL.length > 5 && VAL) return true; else return false;",
message: "Please enter a valid Password"
});
jQuery("#ValidConfirmPassword").validate({
expression: "if ((VAL == jQuery('#ValidPassword').val()) && VAL) return true; else return false;",
message: "Confirm password field doesn't match the password field"
});
jQuery("#ValidSelection").validate({
expression: "if (VAL != '0') return true; else return false;",
message: "Please make a selection"
});
jQuery("#ValidMultiSelection").validate({
expression: "if (VAL) return true; else return false;",
message: "Please make a selection"
});
jQuery("#ValidRadio").validate({
expression: "if (isChecked(SelfID)) return true; else return false;",
message: "Please select a radio button"
});
jQuery("#ValidCheckbox").validate({
expression: "if (isChecked(SelfID)) return true; else return false;",
message: "Please check atleast one checkbox"
});
});
/* ]]> */
是的,你可以一起使用它們。 '$'只是'jQuery'的別名。 – j08691 2014-09-18 21:31:56
如果是的話爲什麼只有當我刪除指定的代碼部分時才提交表單? – query 2014-09-18 21:37:00