JQuery - Set Attribute value

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

I have following HTML with two elements having the same name




        
6条回答
  •  悲&欢浪女
    2021-02-05 02:50

    Some things before the actual code..

    the hash (#) you use as the selector is for IDs and not for names of elements. also the disabled attribute is not a true false scenario .. if it has disabled attribute it means that it is true .. you need to remove the attribute and not set it to false. Also there are the form selectors that identify specific types of items in a form ..

    so the code would be

    $("input:checkbox[name='chk0']").removeAttr('disabled');
    

    Bringing the answer up-to-date

    You should use the .prop() method (added since v1.6)

    $("input:checkbox[name='chk0']").prop('disabled', false); // to enable the checkbox
    

    and

    $("input:checkbox[name='chk0']").prop('disabled', true); // to disable the checkbox
    

提交回复
热议问题