原生js怎么绑定class
1 回答
饮歌长啸
TA贡献1951条经验 获得超3个赞
window.onload = function(){ if(!document.getElementsByClassName){ document.getElementsByClassName = function (cls){ var ret = []; var els = document.getElementsByTagName('*'); for(var i = 0 ; i < els.length; i++){ if(els[i].className === cls || els[i].className.indexOf(cls + ' ') > -1 || els[i].className.indexOf(' ' + cls + ' ') > -1 || els[i].className.indexOf(' ' + cls) > -1){ ret.push(els[i]); } } return ret; } } var checkInput = document.getElementsByClassName("check"); alert(checkInput.length); }
添加回答
举报
0/150
提交
取消