13. Detecting the left and right mouse buttons
$ (function() { $ (' #XY '). MouseDown (function(e) { // 1 = Left key, 2= Middle Key, 3 = right-click }) })
14. Enter Submit Form
$ (function() { $ (' input '). KeyUp (function(e) { if (E.which = = ' + ') { alert (' enter submit! ') ); } }) })
15. Setting Global AJAX parameters
$ (function() { $ (' #load '). Ajaxstart (function() { // Show loading // Disable button }); $ (' #load '). Ajaxcomplete (function() { // Hide loading // Enable button }); })
16. Get the selected drop-down box
$ (function() { //var val = $ (' #select '). Find (' option:selected '). Val (); var val = $ (' #select option:selected '). Val (); Alert (val); })
17. Toggle check box
$ (function() { varfalse; $ (' button '). Click (function() { $ (' input[type=checkbox] '). attr ("Checked",! TOG); = ! tog; }) })
18. Use siblings () to select sibling elements
// Method 1 $ ("#nav li"). Click (function () { $ ("#nav li"). Removeclass (' BG '); $ (this). addclass (' BG '); }) // Method 2: Use siblings () $ ("#nav li"). Click (function () { $ (this). addclass (' bg'). siblings (). Removeclass (' BG '); }) })
19. Personalization Links
$ (function() { $ (//)all elements ending with "red" $ ("a[href$= ' green '"). AddClass (' Bggreen '); $ ("a[href$= ' Blue ']"). AddClass (' Bgblue '); })
20. Automatically hide or close elements after a certain period of time
$ (function() { setTimeout (function() { $ ('. Div1 '). FadeOut () },+); // use Delay () after version 1.4 to implement $ ('. Div2 '). Delay (+). FadeOut (); })
21. Use Firefox or Firebug to log event logs
// $ (' #someDiv '). log (' div '); function (msg) { if (console) { console.log (this) } Returnthis; }
jquery Tips (iii)