jQuery之CSS选择器的处理机制

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>jQuery的第一个demo</title>
<script src="js/jquery-2.1.1.min.js" rel="script"></script>
<script>
$(document).ready(function () {
var btn=document.getElementById("btn");//获取主d为btn的元素(button)
btn .onclick = function(){//给元素添加onel主ek事件
var arrays= new Array();//创建一个数组对象
var items=document .getElementsByName("check");
//获取name为eheek的一组元素(ehee比ox)
for(i=0;i<items .length;i++){//循环这组数据
if(items[i].checked){//判断是否选中
arrays .push(items[i].value);//把符合条件的数据添加到数组中
//push()是Javaser主pt数组中的方法
}
}
alert("选中的个数为:"+arrays .length);
}
})

</script>
</head>
<body>
<input type="checkbox" value="check1" name="check" checked/>
<input type="checkbox" value="check2" name="check"/>
<input type="checkbox" value="check3" name="check" checked/>
<input type="checkbox" value="check4" name="check"/>
<input type="button" value="点击我" id="btn" style="width: 80px; background: #f00; height: 30px; color: #fff;border-color: #f00;">
</body>
</html>

猜你喜欢

转载自www.cnblogs.com/LindaBlog/p/9792411.html