jQuery中的end()方法
定义和用法
end() 方法结束当前链条中的最近的筛选操作,并将匹配元素集还原为之前的状态。
以上是官方说法,比较难理解。
还是用一个例子来说明
<!DOCTYPE html>
<html>
<head>
<style>p { margin:10px; padding:10px; }</style>
<script type="text/javascript" src="/jquery/jquery.js"></script>
</head> <body>
<p><span>Hello</span>, how are you?</p>
<script>$("p").find("span").end().css("border", "2px red solid");</script>
</body>
</html> $("p").find("span")表示查找P元素下的SPAN元素 但是我想更改P的边框,这时我就要返回到P元素(即从SPAN返回到P,就是还原为之前的状态) $("p").find("span").end()这个语句就返回来了。 $("p").find("span").end().css("border", "2px red solid")把P的边框设置了。 ------------------- 对于end()方法,jQuery文档是这样解释的:jQuery回到最近的一个"破坏性"操作 之前。即: 将匹配的元素列表变为前一次的状态。 但给的例子并不是很明显,相信不少人并没有理解它的用法。 下边我们以一个非常简单的例子来说明下用法,html代码如下: <div id="test">
<h1>jQuery end()方法</h1>
<p>讲解jQuery中end()方法。</p>
</div>
JS代码: $(document).ready(function() {
$("#test").click(function() {
$(this).find("p").hide().end().hide();
});
});
点击id为test的div时,首先找到div里边的p标签,将其隐藏。接下来使用end()方法结束了对p标签的引用,此时返回的是#test(jQuery对象),从而后边的hide()方法隐藏了div。这样相信大家已经理解了jQuery中end()方法。
---------------------- <script type="text/javascript" src="jquery.js"></script>
<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>
<style type="text/css">
.panel{
padding:20px; color:#FFFFFF;
font-weight:bold;
width:200px;
height:50px;
}
</style>
<div class="panel">welcome to jQuery!</div>
jQuery中的end()方法的更多相关文章
- jquery 中一些 特殊方法 的特殊使用 一览表
cnblogs的页面, 一种是管理页面, 是随笔的列表 a full list of essays. 另一种是 首页. 要搜索文档的话, 就使用 "首页"的那种方式. 一个jque ...
- 解决关于jquery中$.get()方法总是报“HierarchyRequestError: Node cannot be inserted at the specified point in the hierarchy”错的方法
解决关于jquery中$.get()方法总是报“HierarchyRequestError: Node cannot be inserted at the specified point in the ...
- jQuery中的join方法
和JS 中的JOIN 方法一样,将一数组按照JOIN的参数连接起来.比如: var arr = [ "a", "b", "c", " ...
- jquery中的index方法
问题描述:灵活使用jquery中的index方法 方法签名:index([selector|element]) 用法概述:P1.index(P2) //调用者P1可以为对象或集合 参数为空,返回P1 ...
- 用JQuery中的Ajax方法获取web service等后台程序中的方法
用JQuery中的Ajax方法获取web service等后台程序中的方法 1.准备需要被前台html页面调用的web Service,这里我们就用ws来代替了,代码如下: using System; ...
- jQuery中的ready方法及实现按需加载css,js
模拟jQuery中的ready方法及实现按需加载css,js 一.ready函数的实现 经常用jQuery类库或其他类库中的ready方法,有时候想想它们到底是怎么实现的,但是看了一下jQuery中的 ...
- $.ajax()方法详解 jquery中的ajax方法
jquery中的ajax方法参数总是记不住,这里记录一下. 1.url: 要求为String类型的参数,(默认为当前页地址)发送请求的地址. 2.type: 要求为String类型的参数,请求方式(p ...
- jQuery中的$.ajax()方法
jQuery中的$.ajax()方法 $.ajax({ type:"POST", url:"../page/user.action?userId=" + use ...
- jquery中的ajax方法参数
引用来自:http://www.cnblogs.com/tylerdonet/p/3520862.html jquery中的ajax方法参数总是记不住,这里记录一下. 1.url: 要求为String ...
- HTML5中的data-*属性和jQuery中的.data()方法使用
原文地址链接:http://blog.csdn.net/fly_zxy/article/details/50687691: HTML5中的data-*属性 我们往往会根据需要在HTML标记上添加自定义 ...
随机推荐
- Java关键字final、static使用总结(转)
原文链接:Java关键字final, static一些要点 1. final final类不能被继承,没有子类,final类中的方法默认是final的 final方法不能被子类的方法复盖,但可以被 ...
- python读写json+字典保存
解决方案 json 模块提供了一种很简单的方式来编码和解码JSON数据. 其中两个主要的函数是 json.dumps()和 json.loads() , 要比其他序列化函数库如pickle的接口少得多 ...
- C# 线程 在 sleep,suspend 之后 Abort 的方法
1) 线程在sleep时的Abort 方法:对线程函数用 catch ThreadAbortException ,并return. 示例: [csharp] view plaincopy ...
- [Unity动画]05.Entry & Exit & Any State
0.状态机如下: Any State->Dying:isDying为true Dying->Reviving:isDying为false Reviving->Exit:isDying ...
- fabric-ca1.03安装
前面的文档已经成功的安装了fabric1.0.1的e2e例子.之后代码换成1.0.3版本按步骤重新安装一下,就可以切换到1.0.3了.1.0.3的脚本和启动命令没有变化,还是用的1.0.1的. 1.准 ...
- 5、申请开发(Development)描述文件
申请开发(Development)描述文件 在“Certificates, Identifiers & Profiles”页面“Provisioning Profiles”下选择“Develo ...
- <Linux> Ubuntu error: ssh: connect to host master port 22: No route to host lost connection
iptables当找到匹配的规则时,就会执行相应的动作,而不会向下继续匹配.因为ssh端口开放的规则在all规则之后,所以永远都不会匹配到,也就是ssh永远被禁止. root下执行:iptables ...
- tkinter 布局
- Apache- DBUtils框架学习
一.DBUtils DBUtils 的介绍 commons-dbutils 是 Apache 组织提供的一个开源 JDBC工具类库,它是对JDBC的简单封装,,DBUtils封装了对JDBC的操作,简 ...
- 17. 判断是否IE浏览器
var isNotIE = !window.VBArray; //判断是否IE浏览器 if(isNotIE) { //如果不是IE浏览器 $("#da ...