回調函數的index都有什么用
removeClass(function(index,className)?
回調函數的參數className接受到該元素的類名"aa bb imoocClass",參數類型為字符串。?
index想了好久,這東西有什么用?
下去后測試了下,className隨著索引對元素的類名進行相加。
????<h2>通過jQuery?remove方法移除元素</h2> ????<div?class="right"> ????<div?class="test1"> ????????<p>p元素1</p> ????????<p>p元素2</p> ????</div> ????<div?class="test2"> ????????<p>p元素3</p> ????????<p>p元素4</p> ????</div> </div> <script?type="text/javascript"> $('.right?>?div').removeClass(function(index,className){ ????????????console.log(index); ????????????console.log(className); ????????????$(this).next().addClass(className) ????????????return//不返回任何值 ????????}) </script>
2016-09-18
index是代表之前用$('.right > div:first')查詢得到的對象的索引號。這索引號從0開始,如果index為0說明這是得到的對象里的第一個,index為1,說明是查詢到結果的第二個,以此類推。如果index只有0說明查詢對象的結果只有一個。
換查詢: