![](/img/trans.png)
[英]How to I get the jQuery UI attributes on my elements to get generated after the page has loaded?
[英]jquery hover not called on elements that get the class after page has loaded
我有一個基於MVC的網站的ip驗證,該驗證對IPv4字段進行了“粗略”的前端驗證。 如果ip get更改了,它將在此字段添加圖像和錯誤消息。
但是,這似乎僅適用於來自后端的數據。 數據不正確的字段來自后端,因此在我的Javascript加載之前就已加載。 發生“懸停”事件。 加載后獲得validation-invalid類的字段不具有懸停事件。
我該如何解決這個問題? 我已經嘗試過mouseenter以及mouseleave了。
$(".validation-invalid").hover(function () {
$("#" + $(this)[0].id + "-error").toggle();
});
function validateIPv4(sender) {
var ip = $(sender).val();
var ipformat = /^(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/;
if (ip.match(ipformat)) {
$(sender).removeClass("validation-invalid").addClass("validation-valid");
} else {
$(sender).addClass("validation-invalid").removeClass("validation-valid");
$('<span class="error-popover" id="' + $(sender)[0].id + '-error"><img class="error-callout" src="/Content/images/callout.png" alt="Help pointer">@GlobalizedResources.Device_Configuration_Page_IPv4_Error</span>').insertAfter(sender);
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.