我有一个母版页,在那个母版页中我有:
<form id="form1" runat="server">
<asp:ContentPlaceHolder ID="MainContent" runat="server">
</asp:ContentPlaceHolder>
</form>
我的问题是在我的子页面中我是否需要使用表单元素来实现验证方法?
例如,子格式的脚本:
$("#commentForm").validate({
rules: {
name: "required",
email: "required",
comment: "required"
},
messages: {
name: "Please enter a name",
email: "Please enter an email",
comment: "Enter a comment"
},
submitHandler: function(form) {
form.submit();
}
});
子格式html是:
<div id="commentForm">
<fieldset>
<legend>Please provide your name, email address (won't be published) and a comment</legend>
<div class="form-group">
<label for="cname">Name (required, at least 2 characters)</label>
<input id="cname" class="form-control" name="name" minlength="2" type="text">
</div>
<div class="form-group">
<label for="cemail">E-Mail (required)</label>
<input id="cemail" class="form-control" type="email" name="email">
</div>
<div class="form-group">
<label for="curl">URL (optional)</label>
<input id="curl" class="form-control" type="url" name="url">
</div>
<div class="form-group">
<label for="ccomment">Your comment (required)</label>
<textarea id="ccomment" class="form-control" name="comment" rows="3"></textarea>
</div>
<div class="form-group">
<input class="submit" type="submit" value="Submit">
</div>
</fieldset>
</div>
$("#commentForm").validate
无效。但是,如果我将其切换为$("#form1").validate
,它将会。
由于我无法嵌套表单,是否可以在父表单元素之外的任何其他内容上实现validate方法?
答案 0 :(得分:0)
来自文档:
.validate()
描述:验证所选表格。
所以是的,它假设所选元素是form