jQuery中focusin()与focus()以及find()于children()的区别
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了jQuery中focusin()与focus()以及find()于children()的区别,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含1895字,纯文字阅读大概需要3分钟。
内容图文
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()的区别的详细内容,更多请关注Gxl网其它相关文章!
内容总结
以上是互联网集市为您收集整理的jQuery中focusin()与focus()以及find()于children()的区别全部内容,希望文章能够帮你解决jQuery中focusin()与focus()以及find()于children()的区别所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。