js批量给标签绑定事件
作者:互联网
<div style="width: 50px;height: 50px;background-color: red;"></div><br> <div style="width: 50px;height: 50px;background-color: red;"></div><br> <div style="width: 50px;height: 50px;background-color: red;"></div><br> <div style="width: 50px;height: 50px;background-color: red;"></div> <script> var divs = document.getElementsByTagName('div'); //console.log(divs); for(var i=0;i<divs.length;i++){ divs[i].onclick = function(){ this.style.width = '100px'; this.style.height = '100px'; } } </script>
标签:console,log,标签,绑定,js,getElementsByTagName,var,divs 来源: https://www.cnblogs.com/dazahui/p/14422821.html