weixin_33728268 2013-08-20 04:18 采纳率: 0%
浏览 25

jQuery中未检测到输入

This does not fire the code, and I'm not sure why. I've tried .change, .on('input'), everything I can find. The problem is likely simple. What is wrong?

$(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>
  • 写回答

2条回答 默认 最新

  • 撒拉嘿哟木头 2013-08-20 04:30
    关注

    check this sample. I just removed the "fast" parameter from your .show() call.

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

    From those to calls, let me know if that fix your problem.

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

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

    评论

报告相同问题?

悬赏问题

  • ¥15 安装svn网络有问题怎么办
  • ¥15 Python爬取指定微博话题下的内容,保存为txt
  • ¥15 vue2登录调用后端接口如何实现
  • ¥65 永磁型步进电机PID算法
  • ¥15 sqlite 附加(attach database)加密数据库时,返回26是什么原因呢?
  • ¥88 找成都本地经验丰富懂小程序开发的技术大咖
  • ¥15 如何处理复杂数据表格的除法运算
  • ¥15 如何用stc8h1k08的片子做485数据透传的功能?(关键词-串口)
  • ¥15 有兄弟姐妹会用word插图功能制作类似citespace的图片吗?
  • ¥15 latex怎么处理论文引理引用参考文献