jquery元素操作-36_html

 

<!DOCTYPE html>
<html lang="en">

<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<script src="./js/jquery.min.js"></script>
<style>
div {
width: 100px;
height: 100px;
background-color: pink;
}
</style>
</head>

<body>
<div>1</div>
<div>2</div>
<div>3</div>
<script>
$(function() {
var arr = ["red", "green", "pink"];
var sum = 0;
$("div").each(function(index, domEle) {
//第一个索引号
console.log(index);
console.log(domEle);
$(domEle).css("color", arr[index]);
sum += parseInt($(domEle).text());
})
console.log(sum);
})
</script>
</body>

</html>

运行结果

jquery元素操作-36_html_02