实例一、
<body>
<p><span>Hello</span>, how are you?</p>
<script>$("p").find("span").end().css("border", "2px red solid");</script>
</body>
//说明
//$("p").find("span")表示查找P元素下的SPAN元素
//但是我想更改P的边框,这时我就要返回到P元素(即从SPAN返回到P,就是还原为之前的状态)
//$("p").find("span").end()这个语句就返回来了。
//$("p").find("span").end().css("border", "2px red solid")把P的边框设置了。
实例二、
<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>
//说明 //点击id为test的div时,首先找到div里边的p标签,将其隐藏。 //接下来使用end()方法结束了对p标签的引用,此时返回的是#test(jQuery对象),从而后边的hide()方法隐藏了div。
实例三、
<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
亿速云「云服务器」,即开即用、新一代英特尔至强铂金CPU、三副本存储NVMe SSD云盘,价格低至29元/月。点击查看>>
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。