Checkbox shows hidden field - not working onload

后端 未结 3 1195
星月不相逢
星月不相逢 2021-01-28 03:01

I am using this probably ugly javascript to show a text box (in a li tag plus its label) if a checkbox is checked.

   $(\"#li-2-21\").css(\"display\",\"none\");
         


        
3条回答
  •  北海茫月
    2021-01-28 03:22

    Most concisely:

    $(document).ready(function() {
       $("#Languages-spoken-and-understood-8").change(function() {
          $("#li-2-21")[$(this).is(":checked") ? 'show' : 'hide']("fast")
      }).change();
    });
    

    EDIT : switched from click to change event

提交回复
热议问题