最新文章专题视频专题问答1问答10问答100问答1000问答2000关键字专题1关键字专题50关键字专题500关键字专题1500TAG最新视频文章推荐1 推荐3 推荐5 推荐7 推荐9 推荐11 推荐13 推荐15 推荐17 推荐19 推荐21 推荐23 推荐25 推荐27 推荐29 推荐31 推荐33 推荐35 推荐37视频文章20视频文章30视频文章40视频文章50视频文章60 视频文章70视频文章80视频文章90视频文章100视频文章120视频文章140 视频2关键字专题关键字专题tag2tag3文章专题文章专题2文章索引1文章索引2文章索引3文章索引4文章索引5123456789101112131415文章专题3
当前位置: 首页 - 科技 - 知识百科 - 正文

jQuery中focusin()与focus()以及find()于children()的区别

来源:懂视网 责编:小采 时间:2020-11-27 20:18:27
文档

jQuery中focusin()与focus()以及find()于children()的区别

jQuery中focusin()与focus()以及find()于children()的区别:jQuery中focus()和focusin()、focus()和children()的区别focus()和focusin()focus()和focusin()的区别在于focusin()支持事件的冒泡,下面举例说明:<!doctype html><html lang="en"><
推荐度:
导读jQuery中focusin()与focus()以及find()于children()的区别:jQuery中focus()和focusin()、focus()和children()的区别focus()和focusin()focus()和focusin()的区别在于focusin()支持事件的冒泡,下面举例说明:<!doctype html><html lang="en"><

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()的区别

jQuery中focusin()与focus()以及find()于children()的区别:jQuery中focus()和focusin()、focus()和children()的区别focus()和focusin()focus()和focusin()的区别在于focusin()支持事件的冒泡,下面举例说明:<!doctype html><html lang="en"><
推荐度:
标签: fo jQuery jquery中
  • 热门焦点

最新推荐

猜你喜欢

热门推荐

专题
Top