Disable button in jQuery

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

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

11条回答
  •  野性不改
    2020-11-28 02:46

    This is the simplest way in my opinion:

    // All buttons where id contains 'rbutton_'
    const $buttons = $("button[id*='rbutton_']");
    
    //Selected button onclick
    $buttons.click(function() {
        $(this).prop('disabled', true); //disable clicked button
    });
    
    //Enable button onclick
    $('#enable').click(() =>
        $buttons.prop('disabled', false) //enable all buttons
    );
    
    
    
    
    
    
    
    

提交回复
热议问题