簡體   English   中英

jQuery .blur不起作用

[英]jQuery .blur doesn't work

我有3個模糊對象,由於某種原因,只有第一個可用。 這是jQuery代碼:

<script type='text/javascript'>
    $(document).ready(function() {
        $("#user_name").blur(function() {
            if ($(this).val().length > 4) {
                $("#usernamecheckbox").html("<img src='images/checkmark.png' alt='' />");
            } else {
                $("#usernamecheckbox").html("<img src='images/xmark.png' alt='' />");
            }
        });
        $("#pass").blur(function() {
            if ($(this).val().length < 4) {
                $("#passcheckbox").html("<img src='images/xmark.png' alt='' />");
            } 
        });
        $("#confirmpass").blur(function() {
            if ($(this).val() != $("#pass").val()){
                $("#passcheckbox").html("<img src='images/xmark.png' alt='' />");
            } else {
                $("#passcheckbox").html("<img src='images/checkmark.png' alt='' />");
            }
        });
    });
</script>

形式如下:

<form  enctype="multipart/form-data" method='post' action='reg.php'>
    <input type="hidden" name="MAX_FILE_SIZE" value="1000000" />
    <p>Username <span class='sub'>must be atleast 4 characters</span></p>
    <input type='text' name='user_name' id='user_name' /> <div id='usernamecheckbox' class='checkbox'></div><br />
    <p>Password <span class='sub'>must be atleast 4 characters</span></p>
    <input type='password' id='pass' name='pass' /> &nbsp; <input type='password' name='confirm' id='confirmpass' /> <div id='passwordcheckbox' class='checkbox'></div><br />
    <p>E-mail <span class='sub'>must be a valid E-mail address</span></p>
    <input type='text' name='email' id='email' size='40' /> <div id='emailcheckbox' class='checkbox'></div><br />
    <p>Avatar</p>
    <input type='file' name='avatar' /><br /><br />
    <?php
    require_once('recaptchalib.php');
    $publickey = "6LdLYwcAAAAAAEeupJKr_IBviIq-xHX5W98IacgZ"; // you got this from the signup page
    echo recaptcha_get_html($publickey);
    ?>
    <br />
    <input type='submit' value='Submit'>
</form>

在假定blur()不起作用之前,您應該使用一些簡單的代碼對其進行測試,例如:

$("#pass").blur(function() {
            alert('#pass blur triggered');
    });

我認為問題是您正在尋找$(“#passcheckbox”)。 我在您的HTML id="passcheckbox" 看起來您的意思是$( "#passwordcheckbox")

將#passcheckbox更改為#passwordcheckbox

其余代碼對我來說看起來不錯。

通常,我只是將css添加到jquery選擇器鏈中,以查看它們是否已正確選擇:

$('#passcheckbox').css({'background-color':'red'}).etc();

暫無
暫無

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

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