jQuery中focus()和focusin()、focus()和children()的差别

focus()和focusin()

focus()和focusin()的差别在于focusin()支持事件的冒泡。以下举例说明:

<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>focusin demo</title>
<style>
span {
display: none;
}
</style>
<script src="https://code.jquery.com/jquery-1.10.2.js"></script>
</head>
<body> <p><input type="text"> <span>focusin fire</span></p>
<p><input type="password"> <span>focusin fire</span></p> <script>
$( "p" ).focusin(function() {
$( this ).find( "span" ).css( "display", "inline" ).fadeOut( 1000 );
});
</script> </body>
</html>

当我们点击输入框时。其获得焦点。导致获得焦点事件向上冒泡,使得p标签触发获得焦点事件,而focus()并不支持事件冒泡,相同地。focusout()支持事件冒泡,而blur()不支持。

find()和children()

find()和children()的差别在于find()向下追溯多级子节点,而children()仅仅向下追溯一级子节点。find()和children()相同的地方是他们在寻找子节点时都不包括自身节点。

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
<style type="text/css">
p{
font-size: 20px;
width: 200px;
color: blue;
font-weight: bold;
margin: 0 10px;
}
.hilite {
background: yellow;
}
#test{
font-weight: bolder;
}
</style>
</head>
<body>
<ul class="level-1">
<li class="item-i">I</li>
<li class="item-ii">II
<ul class="level-2">
<li class="item-a">A</li>
<li class="item-b">B
<ul class="level-3">
<li class="item-1">1</li>
<li class="item-2">2</li>
<li class="item-3">3</li>
</ul>
</li>
<li class="item-c">C</li>
</ul>
</li>
<li class="item-iii">III</li>
</ul>
<script src="jquery-2.1.4.js"></script>
<script>
$( "li.item-ii" ).find( "li" ).css( "background-color", "red" );
</script> </body>
</html>

倘若将上例中的find()替换为children(),会得到不同的结果。

jQuery中focusin()和focus()、find()和children()的差别的更多相关文章

  1. jQuery中val()、text()、html()之间的差别

    一.括号里没有值时表示取值    val获取表单中的值: text获取对象中的文本内容,不包含html标签: html获取对象中的内容,包括html标签 <!DOCTYPE HTML> & ...

  2. 基于jquery中children()与find()的区别介绍

    本篇文章介绍了,基于jquery中children()与find()的区别,需要的朋友参考下 .children(selector) 方法是返回匹配元素集合中每个元素的所有子元素(仅儿子辈).参数可选 ...

  3. jquery 中后代遍历之children、find区别

    jquery 中children.find区别 首先看一段HTML代码,如下: <table id="tb"> <tr> <td>0</t ...

  4. jQuery中的常用方法:empty()、each()、$.each()、$.trim()、focus()(二)

    <!DOCTYPE html> <html> <head> <title>02_commonMethod.html</title> < ...

  5. 1. jQuery中的DOM操作

    1)查找节点 通过jQuery选择器来完成 2)创建节点 创建元素节点:var newTd = $("<td></td>") 创建文本节点:在创建元素节点时 ...

  6. 解决上一篇jquery中on的疑惑

    内容都是来自:http://www.365mini.com/page/jquery-on.htm.这里做一下收藏.文章的最后  疑问和解答可以解决所有的疑惑  看了之后能更好的整篇文章. on()函数 ...

  7. jQuery中bind方法和live方法区别解析

    Javascript中的事件有它的独特性,有默认的执行事件,例如冒泡就是其中的一个.在很多比较复杂的应用程序中,停止事件的冒泡或捕获在程序开发当中是十分有用的,而在IE中有它的独特方式来阻止事件的冒泡 ...

  8. jQuery中的bind() live() delegate()之间区别分析

    jQuery中的bind() live() delegate()之间区别分析 首先,你得要了解我们的事件冒泡(事件传播)的概念,我先看一张图 1.bind方式 $('a').bind('click', ...

  9. 深入理解jQuery中live与bind方法的区别

    本篇文章主要是对jQuery中live与bind方法的区别进行了详细的分析介绍,需要的朋友可以过来参考下,希望对大家有所帮助 注意如果是通过jq添加的层和对象一定要用live(),用其他的都不起作用 ...

随机推荐

  1. Grace Hopper 葛丽丝 霍普

    Grace Murray Hopper(1906-1992), COBOL之母, Debug之母, A ship in port is safe, but that is not what ships ...

  2. Google C++ style guide——格式

    1.行长度 每一行代码字符数不超过80. 例外: 1)假设一行凝视包括了超过80字符的命令或URL,出于复制粘贴的方便能够超过80字符: 2)包括长路径的能够超出80列,尽量避免: 3)头文件保护能够 ...

  3. 【转】详述iOS国际化

    原文网址:http://www.cocoachina.com/ios/20151120/14258.html 在真正将国际化实践前,只知道通过NSLocalizedString方法将相应语言的字符串加 ...

  4. js最简单的-点击小图放大

    js最简单的-点击小图放大 标签(空格分隔): js <html> <body> <img class="imgview" src="{$v ...

  5. 迭代Iterator的用法

    迭代→遍历: 一个标准化遍历各类容器里面的所有对象的方法类(典型的设计模式) 把访问逻辑从不同类型的集合类中抽象出来,从而避免向客户端暴露集合的内部结构 迭代(Iterator)与枚举(Enumera ...

  6. Java 系列之spring学习--springmvc注解参数传递(六)

    一.绑定参数注解如下 @RequestParam     绑定单个请求数据,既可以是URL中的参数,也可以是表单提交的参数或上传的文件. 它有三个属性:  value    用于设置参数名. defa ...

  7. c#将http调用返回额json中的有关中文的unicode转换为中文

    c#将http调用返回额json中的有关中文的unicode转换为中文 中文转Unicode:HttpUtility.UrlEncodeUnicode(string str);转换后中文格式:&quo ...

  8. .NET Datatable常用系列一

    Datatable常用系列一 一.用作集合存储数据: DataTable dt = new DataTable("action"); for (int i = 0; i < ...

  9. 401 - Unauthorized: Access is denied due to invalid credentials.

    solution:change application pool from ApplicationPoolIdentity to NetworkService.

  10. Win8 Windows Defender default behaviour

    Problem Description ********************* Is it possible, to change the default behaviour when findi ...