jquery Tips (i)

Source: Internet
Author: User

1. Disable the right-click menu for the page

$ (document). Ready (function () {           $ (document). Bind ("contextmenu", Function (e) {               returnfalse;           })       })

2. New Window open page

$ (document). The hyperlink for Ready (function()       {// Example 1:href= "/http" will open in a new window        $ (' A [href^= "http://"] '). attr ("target", "_blank");        // example 2:rel= "external" hyperlink will open        in a new window $ (' a[rel$= ' external "]). Click (function()            {this. target =" _blank ";        })    })

3. Determine browser type

$(function(){        varBrow =$.browser; //Firefox 2 and above        if(Brow.mozilla && brow.version>= "1.8") {alert ("Firefox"); }        //Safari        if(Brow.safari) {alert ("Safari"); }        //Chrome        if(brow.chrome) {alert ("Chrome"); }        //Opera        if(Brow.opera) {alert ("Opera"); }        //IE6 and below        if(Brow.msie && brow.version <= 6) {alert ("<=ie6"); }        //above IE6        if(Brow.msie && brow.version > 6) {alert (">ie6"); }    })
After the JQ 1.3 version, the official recommendation is to use $.support instead of $.browser
Note: The above method does not apply to versions 1.9 and above

4. Input box text get and lose focus
$(function(){            $(' Input.text1 '). Val (' Enter your search text here '); Textfill ($ (' Input.text1 ')); })        functionTextfill (input) {varOriginalValue =Input.val (); Input.focus (function(){                if($.trim (Input.val ()) = = OriginalValue) {//If the input box is the original content, click Empty value to make it easy to enterInput.val (' '); }}). blur (function(){                if($.trim (Input.val ()) = = ") {//If the input box content is empty, that is, the previous click did not enter, the mouse left to restore the original contentInput.val (OriginalValue); }            })        }

5. Return to head slide animation

function (speed) {        var targetoffset = $ (this). Offset (). Top;        $ (' html,body '). Stop (). Animate ({scrolltop:targetoffset},speed);         return  This ;    }    $ ("#goHeader"). Click (function  () {        $ ("body"). ScrollTo;         return FAL

6. Get the mouse position

$ (function() {        $ (document). MouseMove (function(e) {            $ ("#XY"). HTML ("X: "+ e.pagex+" | Y: "+ E.pagey);})    })

jquery Tips (i)

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.