How to implement “select all” check box in HTML?

前端 未结 29 2870
悲哀的现实
悲哀的现实 2020-11-22 11:09

I have an HTML page with multiple checkboxes.

I need one more checkbox by the name \"select all\". When I select this checkbox all checkboxes in the HTML page must b

29条回答
  •  醉梦人生
    2020-11-22 11:33

    I'm not sure anyone hasn't answered in this way (using jQuery):

      $( '#container .toggle-button' ).click( function () {
        $( '#container input[type="checkbox"]' ).prop('checked', this.checked)
      })
    

    It's clean, has no loops or if/else clauses and works as a charm.

提交回复
热议问题