[英]jQuery.validate errorPosition not working correctly
jQuery.validate errorPosition代碼 :
errorPlacement:
function(error, element)
{
error.appendTo(element.siblings("label"));
},
當標簽下面只有一個元素時,該代碼將非常有效。
不起作用:
<label for="location">Location:</label><br />
<div id="location"></div><br />
<input name="location" id="h_location" hidden /><br />
這有效:
<label for="location">Location:</label><br />
<input name="location" id="h_location" hidden /><br />
當div位置不存在時,錯誤會顯示在位置標簽旁邊。 當位置div出現時,錯誤消息根本不顯示。
我一直在尋求幫助,有人向我提到我應該閱讀CSS塊級元素。 我仔細閱讀了它們,但沒有找到解決方案。 我從閱讀中收集的全部內容是如何顯示:內聯,阻止或不顯示。 我顯然不明白那個人在暗示什么。
為什么錯誤消息什么時候不顯示?如何顯示?
-謝謝你,有錢人
我找到了一種將錯誤消息附加到標簽的方法:
var elementName = element.attr("name");
error.appendTo($("label[for=" + elementName + "]"));
那按預期工作。
我仍然對實現此目標的其他方式持開放態度。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.