您好,登錄后才能下訂單哦!
實(shí)例一、
<body> <p><span>Hello</span>, how are you?</p> <script>$("p").find("span").end().css("border", "2px red solid");</script> </body> //說(shuō)明 //$("p").find("span")表示查找P元素下的SPAN元素 //但是我想更改P的邊框,這時(shí)我就要返回到P元素(即從SPAN返回到P,就是還原為之前的狀態(tài)) //$("p").find("span").end()這個(gè)語(yǔ)句就返回來(lái)了。 //$("p").find("span").end().css("border", "2px red solid")把P的邊框設(shè)置了。
實(shí)例二、
<div id="test"> <h2>jQuery end()方法</h2> <p>講解jQuery中end()方法。</p> </div> <scripg> $(document).ready(function() { $("#test").click(function() { $(this).find("p").hide().end().hide(); }); }); </script> //說(shuō)明 //點(diǎn)擊id為test的div時(shí),首先找到div里邊的p標(biāo)簽,將其隱藏。 //接下來(lái)使用end()方法結(jié)束了對(duì)p標(biāo)簽的引用,此時(shí)返回的是#test(jQuery對(duì)象),從而后邊的hide()方法隱藏了div。
實(shí)例三、
<script type="text/javascript"> $(function(){ $('<input type="button" value="click me" /><input type="button" value="triggle click me" /><input type="button" value="detach handle" /><input type="button" value="show/hide text" />').appendTo($('body')); $('input[type="button"]').eq(0).click(function(){ alert('you clicked me!'); }) .end().eq(1).click(function(){ $('input[type="button"]:eq(0)').trigger('click'); }) .end().eq(2).click(function(){ $('input[typw="button"]:eq(0)').unbind('click'); }) .end().eq(3).toggle(function(){ $('.panel').hide('slow'); },function(){ $('.panel').show('slow'); }); }) </script> <div class="panel">welcome to jQuery!</div>
參考資料: jQuery end() http://www.studyofnet.com/news/932.html
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。