jq的链式调用.end();
生活随笔
收集整理的這篇文章主要介紹了
jq的链式调用.end();
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
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張 閱讀(...) 評論(...) 編輯 收藏轉載于:https://www.cnblogs.com/vivenZ/p/6411749.html
總結
以上是生活随笔為你收集整理的jq的链式调用.end();的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 大话设计模式读书笔记--6.原型模式
- 下一篇: whmcs模板路径