我有一个在单击事件后在对话框内打开的表单。我想知道我的 jquery 中是否存在我没有注意到的语法问题。提交处理程序函数中的所有日志都没有记录。
HTML:
<div id="dialog" title="Thanks For Volunteering">
<form>
<p>Please provide a contact number. It will only be shared with the comic</p>
<input id="number" name="number" type="text" />
<button id="submit" class="button">Submit</button>
</form>
</div>
JavaScript:
$("form").submit(function(){
console.log("submit");
$('#number').validate({
rules: {
number : {
required: true
//customvalidation: true
}
},
messages: {
number : {
required: "enter a phone number"
}
},
submitHandler: function(form) {
// do other stuff for a valid form
//submit to parse
console.log("now validated");
var num = $('#number').val();
console.log("validated:" +' '+num);
}
});
});//closes submit
$.validator.addMethod("customvalidation",
function(value, element) {
return (/^[A-Za-z\d=#$%@_]+$/.test(value));
},
"Sorry, no special characters allowed");