Jquery验证似乎忽略了验证部分由于某些原因我不确定。我正在使用带有纯HTML控件的asp.net母版页和敲除绑定我删除了代码以使其更具可读性。我该怎么办才能使验证成为可能。
母版页代码
<head runat="server">
<title></title>
<meta name="viewport" content="width=device-width, user-scalable=yes">
<script type='text/javascript' src="//cdnjs.cloudflare.com/ajax/libs/jquery/1.10.2/jquery.js"></script>
<script type='text/javascript' src="//cdnjs.cloudflare.com/ajax/libs/jqueryui/1.10.2/jquery-ui.js"></script>
<link rel="stylesheet" href="http://code.jquery.com/ui/1.10.3/themes/smoothness/jquery-ui.css" />
<script type='text/javascript' src='//cdnjs.cloudflare.com/ajax/libs/knockout/3.1.0/knockout-min.js'></script>
<script type="text/javascript" src="http://ajax.aspnetcdn.com/ajax/jquery.validate/1.11.1/jquery.validate.min.js"></script>
<script type="text/javascript" src="http://ajax.aspnetcdn.com/ajax/jquery.validate/1.11.1/additional-methods.min.js"></script>
<asp:ContentPlaceHolder ID="HeadContent" runat="server">
</asp:ContentPlaceHolder>
</head>
<body>
<form id="form1" runat="server">
</form>
</body>
内容页面和Jquery插件
<asp:Content ID="Content1" ContentPlaceHolderID="HeadContent" runat="server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
<script type="text/javascript">
$(document).ready(function () {
var istrue= $('#aspForm').validate(
{
rules: {
name:
{
required: true
}
},
messages: {
name:
{
required: "Please enter a name"
}
}
});
});
// **All view models are declare removed**
self.SearchNext = function () {
if ($('#aspForm').valid()) { //<== **always shows true**
}
}
</script>
....
....
....
<div align="center">
<button type="button" id="btnNext" class="submitButton" data-bind="click:SearchNext"> //<== I am using knockout binding here
Next</button>
</div>
</asp:Content>
显示错误
Chrome控制台显示此错误
Uncaught TypeError: Cannot read property 'form' of undefined
更新1
我在内容页面中有这一行
但不是在母版页中会出现问题的一部分