douzhi2760 2013-04-24 01:39
浏览 48
已采纳

如果有错误消息,如何禁用特定按钮?

enter image description here

I have here a create account form, beside my User ID field the one with the Sorry, User ID already exists! is an error message generated by AJAX that notifies the user if the user id he entered obviously exists. Username field here also has the same function with User ID. my problem is how can I disable my Create Button if the error message displayed is Sorry, User ID/ Username already Exist? . by the way the message changes into User ID/ Username available otherwise.

Here is my Jquery code

   $(document).ready(function()
   {
     $('#create_btn').hover(function()
     {
       var id = $('#labeler').val();
       var user = $('#labeler2').val();

    if((id.indexOf('available') >= 0) && user.indexOf('available') >= 0)
    {
        $('#create_btn').removeProp('disabled');
    }
    else
    {
        $('#create_btn').prop('disabled', true);
    }
});
});
  • 写回答

2条回答 默认 最新

  • dongrong9053 2013-04-24 03:02
    关注

    I ended up doing this because the code I used above was able to disable the create button but wasn't able to enable it again because .hover() cant read a disabled button. Thank you for all of your help!

    $(document).ready(function()
    {
        $(':text').blur(function()
        {
            var id = $('#labeler').val();
            var user = $('#labeler2').val();
    
            if((id.indexOf('available') >= 0) && user.indexOf('available') >= 0)
                $('#create_btn').removeProp('disabled');
            else
                $('#create_btn').prop('disabled', true);
        });
    });
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥20 如何通过代码传输视频到亚马逊平台
  • ¥15 php查询mysql数据库并显示至下拉列表中
  • ¥15 freertos下使用外部中断失效
  • ¥15 输入的char字符转为int类型,不是对应的ascall码,如何才能使之转换为对应ascall码?或者使输入的char字符可以正常与其他字符比较?
  • ¥15 devserver配置完 启动服务 无法访问static上的资源
  • ¥15 解决websocket跟c#客户端通信
  • ¥30 Python调用dll文件输出Nan重置dll状态
  • ¥15 浮动div的高度控制问题。
  • ¥66 换电脑后应用程序报错
  • ¥50 array数据同步问题