Solutions for settimeout that do not support jquery

Source: Internet
Author: User

In JS, whether it is settimeout or setinterval, when using the function name as the call handle can not take parameters, and in many cases must be with parameters, this need to solve the method.

Today in writing a JS delay event found in settimeout this method using JQuery's $ (this) unexpectedly does not work, various tests, and finally concluded that the settimeout does not support jquery selector. So consult the QQ to do jquery development master, immediately put this problem solved, here record.

The following is the author's time delay processing of the JS code:

?

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17-18 $ ('. 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);};

Note that the code in the above settimeout code, if the code is not in this method, itself is no problem, but the above situation will be an error. As for the reason, the author is not clear yet. After the user to change to the following is no matter, the method is very ingenious. The following is the correct code:

?

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19-20 $ ('. Dl_select dt '). Hover (function () {cleartimeout (T3); $ (this). Siblings (' DD '). CSS ({' Display ': ' Block ', ' cursor ': ') Pointer '}); The 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 mentioned is the entire content of this article, I hope you can enjoy.

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.