Solutions that do not support jquery selector in setTimeout _ javascript skills

Source: Internet
Author: User
In JS, whether it is setTimeout or setInterval, parameters cannot be included when using the function name as the call handle. In many cases, parameters must be included, which requires a solution. Today, when I wrote a js latency event, I found that the $ (this) of jquery In the setTimeout method did not work. Various tests, the final conclusion is that the setTimeout does not support jquery selector. So I consulted a professional on jquery development on QQ and immediately solved the problem. I will record it here.
Below is the js code used by the author for latency processing:

$('.dl_select dt').hover(   function(){     clearTimeout(t3);     $(this).siblings('dd').css({'display':'block','cursor':'pointer'});   },   function(){     t2=setTimeout(function(){$(this).siblings('dd').css({'display':'none'});},300);   } ); $('.dl_select dd').hover(   function(){     clearTimeout(t2);     $(this).css({'display':'block','cursor':'pointer'});   },   function(){     t3=setTimeout(function(){$(this).css({'display':'none'});},200);   } ); 

Pay attention to the Code in setTimeout in the above Code. If the Code is not in this method, it is no problem, but the above situation will report an error. As for the reason, the author does not understand it now. It's okay to change it to the following after the netizens click it. The method is clever. The following is the correct code:

$('.dl_select dt').hover(   function(){     clearTimeout(t3);     $(this).siblings('dd').css({'display':'block','cursor':'pointer'});   },   function(){     var $this=$(this).siblings('dd');     t2=setTimeout(function(){$this.css({'display':'none'});},300);   } ); $('.dl_select dd').hover(   function(){     clearTimeout(t2);     $(this).css({'display':'block','cursor':'pointer'});   },   function(){     var $this=$(this);     t3=setTimeout(function(){$this.css({'display':'none'});},200);   } ); 

The above is all the content of this article. I hope you will like it.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.