JQuery - Set Attribute value

前端 未结 6 558
旧时难觅i
旧时难觅i 2021-02-05 02:22

I have following HTML with two elements having the same name




        
6条回答
  •  陌清茗
    陌清茗 (楼主)
    2021-02-05 02:45

    Seriously, just don't use jQuery for this. disabled is a boolean property of form elements that works perfectly in every major browser since 1997, and there is no possible way it could be simpler or more intuitive to change whether or not a form element is disabled.

    The simplest way of getting a reference to the checkbox would be to give it an id. Here's my suggested HTML:

    
    
    

    And the line of JavaScript to make the check box enabled:

    document.getElementById("chk0_checkbox").disabled = false;
    

    If you prefer, you can instead use jQuery to get hold of the checkbox:

    $("#chk0_checkbox")[0].disabled = false;
    

提交回复
热议问题