问题二:参考代码中的domEle是一个实参吗,他和我用的$(this)有区别吗。另外我把$(this).css 改成 this.css就不行了,this取得是一个dom对象,css不就是它的 属性吗?
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
<!-- jQuery (V1.11.0) -->
<script src="/new/libs/jquery/jquery.min.js"></script>
<style>
div {
width: 400px;
background-color: aquamarine;
height: 170px;
}
</style>
</head>
<body>
<!-- <img>
<img> -->
<button>start</button>
<span></span>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div id="stop" ></div>
<div></div>
<script>
// $('img').each(function(i){
// var e = i+1
// this.src = '../images/img_3trends_' + e + '.png'
// })
$('button').click(function(){
$('div').each(function(i){
$(this).css('backgroundColor','yellow');
if($(this).is('#stop')){
$('span').text('Stopped at div index' + i);
return false;
}
})
})
//下方为参考代码
// $("button").click(function () {
// $("div").each(function (index, domEle) {
// // domEle == this
// $(domEle).css("backgroundColor", "yellow");
// if ($(this).is("#stop")) {
// $("span").text("Stopped at div index #" + index);
// return false;
// }
// });
// });
</script>
</body>
</html>