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

前端 未结 29 2875
悲哀的现实
悲哀的现实 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:55

    
    
     Toggle All
    Bar 1
    Bar 2
    Bar 3
    Bar 4

    UPDATE:

    The for each...in construct doesn't seem to work, at least in this case, in Safari 5 or Chrome 5. This code should work in all browsers:

    function toggle(source) {
      checkboxes = document.getElementsByName('foo');
      for(var i=0, n=checkboxes.length;i

提交回复
热议问题