我使用jQuery的bassistance驗證插件。jquery驗證點擊事件的錯誤消息
爲了保持窗體清晰,我在無效字段後面僅放置一個字母作爲Errormessage(例如無效格式的「F」)。現在我想通過點擊字母給用戶一個特殊div(#errordetails)中的詳細errormessage選項。
$(".contactForm").validate({
rules ....
}),
...
我希望把這樣的事情:
$("label.error").click(function() {
alert("The Errormessage was clicked ...");
})
我在哪裏必須把這個代碼?
編輯:對不起,我忘了寫這個。在$(document).ready()中,事件不起作用。點擊查看其它元素的事件爲$( 「label.error」)
OK編輯第2部分工作正常,但不是事件:
我的HTML驗證後
:<div class="formField cf">
<label for="contactGeburt">Geb.datum *
<span style="font-size: 10px; color: #999"> (dd.mm.jjjj)
</span>
</label>
<input type="text" maxlength="10" id="gebdatum" name="gebdatum" class="textField datum error">
<label for="gebdatum" generated="true" class="error">
<span class="errorvalue">P
</span>
</label>
這裏是jQuery的部分
$(document).ready(function(){
$(".contactForm").validate({
rules: {
gebdatum: {
required: true,
dateDE: true
}
},
}),
//This does not work
$(function() {
$("label.error").click(function() {
alert("The Errormessage was clicked ...");
});
});
// This works - H1 is also on the document ;-)
$(function() {
$("h1").click(function() {
alert("H1 was clicked ...");
});
});
});
編輯第3部分:
感謝您的支持:
從來就測試的(有效)的代碼,但它doesn't工作。從來就開始從bassistance的demopage:
http://jquery.bassistance.de/validate/demo/
我粘貼功能:
$("label").click(function() {
alert("The Label was clicked ...");
});
...並運行的代碼(控制檯)。在單擊文本框中的標籤時,會顯示alertmessage。點擊「提交」 - 按鈕後,錯誤標籤(紅色)不會對事件做出反應,但輸入字段的標籤會顯示警報框。
所以我再次從控制檯運行代碼(錯誤在屏幕上後),現在顯示了alterbox。
所以我認爲,事件必須放在窗體中的validate事件中,但我不知道正確的語法。
編輯第4部分:
這裏是所有ressorces到的jsfiddle的鏈接包括:http://jsfiddle.net/frank79/HVEXm/
感謝您的幫助!對不起,這個可憐的英語......
如果我明白你的問題,你可以把你的代碼放在'$(document).ready()'塊中。 – JMax
對不起,我忘了寫這個。在$(document).ready()中,事件不起作用。其他元素的點擊事件工作正常,但不是$(「label.error」)的事件.... –
向我們展示您的HTML,例如在jsfiddle中。您可能在選擇器中出現錯誤,尤其是在其他事件發生時 – JMax