Disable/enable element with checkbox and jQuery?

前端 未结 6 1202
自闭症患者
自闭症患者 2020-12-29 11:11

I have a checkbox and if I tick it I want a textfield to become enabled (disabled as default) and when I untick the the checkbox I want it to become disabled again.

6条回答
  •  误落风尘
    2020-12-29 12:10

    @Martin -to delete the text in the textboxes that becomes disabled and untick the checkboxes that becomes disabled - just add this line

     $("#TextField_ID_name").val("");
    

    and to uncheck the checkbox, you need to assign ID name to the checkbox and then add this line to the Jquery

    $("#chekcbox_ID_name").attr('checked',false)
    

    Hope this helps someone ... though I'm replying to Martins question after 2 years since his posting :-)

提交回复
热议问题