Disable button in jQuery

后端 未结 11 1693
时光说笑
时光说笑 2020-11-28 02:04

My page creates multiple buttons as id = \'rbutton_\"+i+\"\'. Below is my code:

相关标签:
11条回答
  • 2020-11-28 02:19

    For Jquery UI buttons this works :

    $("#buttonId").button( "option", "disabled", true | false );
    
    0 讨论(0)
  • 2020-11-28 02:24

    Try this

    function disable(i){
        $("#rbutton_"+i).attr("disabled",true);
    }
    
    0 讨论(0)
  • 2020-11-28 02:25

    Here's how you do it with ajax.

    $("#updatebtn").click(function () {
        $("#updatebtn").prop("disabled", true);
        urlToHandler = 'update.ashx';
                jsonData = data;
                $.ajax({
                    url: urlToHandler,
                    data: jsonData,
                    dataType: 'json',
                    type: 'POST',
                    contentType: 'application/json',
                    success: function (data) {
                        $("#lbl").html(data.response);
                        $("#updatebtn").prop("disabled", false);
                        //setAutocompleteData(data.response);
                    },
                    error: function (data, status, jqXHR) {
                        alert('There was an error.');
                        $("#updatebtn").prop("disabled", false);
                    }
                }); // end $.ajax
    
    0 讨论(0)
  • 2020-11-28 02:26

    disable button:

    $('#button_id').attr('disabled','disabled');
    

    enable button:

    $('#button_id').removeAttr('disabled');
    
    0 讨论(0)
  • 2020-11-28 02:31

    This works for me:

    <script type="text/javascript">
    function change(){
        document.getElementById("submit").disabled = false;
    }
    </script>
    
    0 讨论(0)
  • 2020-11-28 02:32

    I want to disable button on some condition, i am using 1st solution but it won't work for me. But when I use 2nd one it worked.Below are outputs from browser console.

    1. $('#psl2 .btn-continue').prop("disabled", true)

    <a class=​"btn btn-yellow btn-continue" href=​"#">​Next​</a>​
    

    2. $('#psl2 .btn-continue').attr("disabled","disabled")

    <a class=​"btn btn-yellow btn-continue" href=​"#" disabled=​"disabled">​Next​</a>​
    
    0 讨论(0)
提交回复
热议问题