Ello堆棧,無法似乎弄清楚爲什麼沒有任何文本顯示在我的div驗證後的字段。這是我的代碼。我知道驗證正在運行,但是,我不確定爲什麼我的驗證消息沒有顯示在div中。 不知道爲什麼我的div沒有顯示驗證消息
<html>
<head>
<script src="Scripts/jquery-1.5.2.js" type="text/javascript"></script>
<script src="http://localhost:62147/Scripts/jquery.validate.js" type="text/javascript"></script>
<script type="text/javascript">
"use strict";
$(document).ready(function() {
$("#testerbtn").bind("click", function() {
alert("onclick is fired");
$("#myform").validate({
errorLabelContainer: $("#Errors"),
rules: {
textToVal: { required: true }
},
messages: {
textToVal: "the field is required! nub~!"
}
});
alert("validation should have happend.");
})
});
</script>
<title>Test Page</title>
</head>
<body>
<form id = "myform" action="htmlPage1.htm">
<div id="Errors"></div>
<div>
<input type="text" id="textToVal" value="" />
<input type="button" id="testerbtn" value="Tester" />
</div>
</form>
</body>
</html>
'.validate()'有回調嗎? – Blender 2011-04-11 16:45:10
確定要驗證嗎?因爲如果這是複製粘貼的,你有''嚴格使用';'隨機放置在腳本的開頭。 – Khez 2011-04-11 16:47:09
'「使用scrict」'不是一個隨機字符串。閱讀關於嚴格模式:https://developer.mozilla.org/en/JavaScript/Strict_mode – 2011-04-11 16:49:03