jq的鏈式調用.end();
先上code
<!DOCTYPE html> <html lang="en"> <head><meta charset="UTF-8"><title>Title</title><style>li{list-style: none;width: 100px;height:20px;border:1px solid #ff0000;display: inline-block;text-align: center;*display:inline;*zoom:1;}</style> </head> <body><ul id="ul"><li>1</li><!----><li>2</li><!----><li>3</li><!----><li>4</li></ul><script src="http://code.jquery.com/jquery-latest.js"></script><script>$(function(){$("li").eq(0).click(function(){alert(0);}).end().eq(1).click(function(){alert(1);}).end().eq(2).click(function(){alert(2);}).end().eq(3).click(function(){alert(3);});})</script> </body> </html>
在這里可以點擊每個li元素彈出各自的下標。
.end()方法意思就是取消當前的jQuery對象,返回上一層的jQuery對象。在這里的意思就是取消當前選擇的$("li").eq(0);返回上層的$("li")。上圖解釋:
返回的還是li元素的集合。
?
posted on 2017-02-17 22:27 Viven張 閱讀(...) 評論(...) 編輯 收藏