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.