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标记上添加自定义 ...
随机推荐
- 关于dict的formkeys方法注意
使用容器中的元素生成k, v为统一值, 指向同一个内存地址 默认值指向同一个内存, 修改就全部修改 strvar = 'abcd' listvar = [] dictvar = {} dictvar ...
- DB通用类:SQL Server 通用类库
SQLServer通用类A using System; using System.Data; using System.Data.SqlClient; using System.Collections ...
- php创建临时表
$sql= "create temporary table yc_linshi ( img varchar(100) not null, openid varchar(50) not nul ...
- CF1139D Steps to One (莫比乌斯反演 期望dp)
\[ f[1] = 0 \] \[ f[i] = 1 + \frac{1}{m} \sum_{j = 1} ^ n f[gcd(i, j)] \ \ \ \ \ \ (i != 1) \] 然后发现后 ...
- 5种分布式共享session的方法
集群/分布式环境下5种session处理策略 转载 2016年03月16日 08:59:53 标签: session / nginx / 分布式 / 集群 11098 转载自:http://blog. ...
- spring揭密学习笔记(1) --spring的由来
1.spring起源于在EJB暴露出各种严重问题的情况应运而生. Spring是于2003年兴起的一个轻量级的Java开发框架, Spring倡导一切从实际出发,以实用的态度来选择适合当前开发场景的解 ...
- switch的穿透,是参数里包含case内容就执行。
package rom; import java.lang.*; /* * switch的穿透,是参数里包含case内容就执行. */ public class Xamle_5 { public st ...
- LeetCode 11. [👁] Container With Most Water & two pointers
盛最多水的容器 给定 n 个非负整数 a1,a2,...,an,每个数代表坐标中的一个点 (i, ai) .在坐标内画 n 条垂直线,垂直线 i 的两个端点分别为 (i, ai) 和 (i, 0).找 ...
- [转]asp+oracle分页
PageSize:每页显示的记录数.PageCount:根据用户设定好的PageSize和表中的总记录数,系统自动算出总页数.RecordCount:表中的总记录数.AbsolutePage:表示当前 ...
- 基于canvas的电子始终
//code <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <ti ...