比如说同时选中table标签下的thead与tbody
<h3> h3 元素</h3>
<h2> h2 元素</h2>
<script>
var eles = document.querySelectorAll("h2, h3");
var length = eles.length;
for(var i=0; i<length; i++) {
eles[i].style.background = 'red';
}
</script>
可以用原生的 document.querySelectorAll('table thead, table tbody');
或者jQuery方法$('table thead, table tbody');
返回的都是一个节点数组,这个数组就包含了你要选中的几个节点,可以同时对他们进行操作。
document.querySelectorAll("table thead, table tbody");