2013-08-20 112 views
0

這不會觸發代碼,我不知道爲什麼。我試過.change.on('input'),我能找到的所有東西。問題可能很簡單。哪裏不對?jQuery中未檢測到輸入

$(function() { 
    alert('hie'); 
    //the min chars for username 
    var min_chars = 3; 

    //result texts 
    var characters_error = 'Minimum amount of chars is 3'; 
    var checking_html = 'Checking...'; 

    //when button is clicked 
    $('#myusername').bind("change paste keyup", function() { 
     //run the character number check 
     if ($('#myusername').val().length < min_chars) { 
      //if it's bellow the minimum show characters_error text     
      $('#username_availability_result').html(characters_error); 
      $('#checkuser').show(fast); 
      alert('hsdi'); 
     } 
     else { 
      //else show the cheking_text and run the function to check 
      $('#username_availability_result').html(checking_html); 
      $('#checkuser').show(fast); 
      check_availability(); 
      alert('hi'); 
     } 
    }); 
}); 

//function to check username availability 
function check_availability() { 

    //get the username 
    var username = $('#myusername').val(); 
    //use ajax to run the check 
    $.post("../php/checkuser.php", {username: username}, 
    function(result) { 
     //if the result is 1 
     if (result == 1) { 
      //show that the username is available 
      $('#username_availability_result').html(username + ' is Available'); 
     } else { 
      //show that the username is NOT available 
      $('#username_availability_result').html(username + ' is not Available'); 
     } 
    }); 
} 

HTML

<tr> 
    <td>Username</td> 
    <td><input type="text" name="username" placeholder="Username" id="myusername"></td> 
</tr> 
<tr id="checkuser" style="display: none"> 
    <td> 

    </td> 
</tr> 
+0

什麼是不工作... –

+0

在檢測輸入變化的JS輸入#myusername引發其他代碼檢查分貝,如果用戶名是有效的。沒有警報彈出,但js文件正在發出第一個警報。 – user1552172

+0

投票關閉,因爲有一個錯字,這不太可能幫助未來的遊客。 – FakeRainBrigand

回答

2

檢查該樣品。我剛從你的.show()調用中刪除了「fast」參數。

http://jsfiddle.net/juaning/PsvS7/

從那些電話,讓我知道這是否解決您的問題。

$('#checkuser').show(fast);alert('hsdi');

$('#checkuser').show(fast);

+1

是的,它的工作,但又是一個白癡哈哈。非常感謝你。 – user1552172

1

不是100%肯定你是什麼問題,有一些失蹤HTML與代碼走。

但是,在您的js中存在錯誤,您需要快速包圍引號。

$('#checkuser').show('fast'); 

$('#checkuser').show('fast'); 

這將至少讓您的警報顯示出來。