Using JavaScript to manipulate HTML input (checkbox) elements via type instead of name

后端 未结 7 2007
说谎
说谎 2021-01-04 14:41

I am implementing an HTML form with some checkbox input elements, and I want to have a Select All or DeSelect All button. However, I do not want to rely on the name

相关标签:
7条回答
  • 2021-01-04 15:18
    function findCheckBoxes(el, check) {
            for(var i=0;el.childNodes[i];i++)
            {
                var child = el.childNodes[i];
                if (child.type=="checkbox")
                {
                    child.checked = check;
                }
                if (child.childNodes.length > 0)
                    this.findCheckBoxes(child, check);
            }
        }
    
    0 讨论(0)
提交回复
热议问题