jquery Tips (iii)

Source: Internet
Author: User

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)

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.