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

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);
    }
});
});

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);
    });
});

As you are using jQuery, you can do this:

$("#buttonId").prop("disabled",true)

More discussion here

I suspect the labeler/labeler2 are span/div. In that case you should use text(), not val(). Change those lines into:

var id = $('#labeler').text();//user id notification AJAX
var user = $('#labeler2').text();//username notification AJAX