簡體   English   中英

blur()和focus()在帶有replaceWith()的jQuery上不起作用

[英]blur() and focus() not working on jQuery with replaceWith()

我使用的是jQuery表單,當您單擊某個字段時,它將顯示有關在該字段中做什么的提示。

標簽。 使用我現在擁有的代碼,它將對第一個元素起作用,但是之后,如果我嘗試單擊另一個,它將不會覆蓋以前的更改。 我嘗試在模糊時使用empty(),但無法清除任何內容,而且我也不知道這是否真的可以解決問題。 如果有人對我的問題有任何見解,我將不勝感激!

#helpP是我要在其中更改文本的段落。 其他ID只是表單字段。

$(document).ready(function () {
    $("#mail").focus(function() {
        $("#helpP").replaceWith("<p>This e-mail address will be used as your login and for receiving special offers from Volga</p>");
    }).blur(function(){
        $("helpP").empty();
    });

    $("#confirmEmail").focus(function() {
        $("#helpP").replaceWith("<p>Confirm your e-mail</p>");
    });

    $("#confirmEmail").blur(function() {
        $("#helpP").empty();
    });

    $("#passwordReg").focus(function() {
        $("#helpP").replaceWith("<p>Passwords can only have letters and numbers and are case sensitive.</p>");
    });

     $("#passwordRegConfirm").focus(function() {
         $("#helpP").replaceWith("<p>Enter the same password again to ensure accuracy</p>");
     });
 });

我嘗試與第一個鏈接,以查看是否有任何區別,但是沒有。

不要使用replaceWith()嘗試使用html()之類的方法,

$("#mail").focus(function() {
    $("#helpP").html("<p>This e-mail address will be used as your login and for receiving special offers from Volga</p>");
}).blur(function(){
    $("#helpP").empty();// use # before id selector
});

replaceWith()文檔中,

說明:用提供的新內容替換匹配元素集中的每個元素,並返回被刪除的元素集。

而且您的elements將被p elements replaced

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM