jquery tips and tricks that may be used during development

Source: Internet
Author: User

Today, we'll share some useful tips and tricks for jQuery developers. JQuery is one of the best JavaScript libraries for simplifying animations, event handling, and client-side scripting that supports Ajax and HTML . The network has a large number of jQuery plug-ins to help create a Web site in a short period of time through simple and easy methods.

Today we have selected a few pieces of code that are very useful to our team of jQuery developers. Hopefully you'll be able to use the code in your next project.

1) No right button

When developing WEB applications, there are situations where you need to disable the right-click feature. With this code, the JQuery developer can disable the right mouse click on the Web page. The code is as follows:

$ (document). Ready (function () {
    //catch The right-click context menu
    $ (document). Bind ("ContextMenu", function (e) {                
        //warning prompt-optional
        alert ("No right-clicking!");
    
        Delete the default context menu, return false;});

2) Text Scaling

With the following code, the user can increase or scale the font size in the Web page with the following code:

$ (document). Ready (function () {
    //find the current font size
    var originalfontsize = $ (' html '). CSS (' font-size ');
    
    //increase The text size
    $ (". Increasefont"). Click (function () {
        var currentfontsize = $ (' html '). CSS (' Font-size ');
        var currentfontsizenumber = parsefloat (Currentfontsize, ten);
    
        var newfontsize = currentfontsizenumber*1.2;
        $ (' HTML '). CSS (' font-size ', newfontsize);
        return false;
    });
    
    Decrease the Text Size
    $ (". Decreasefont"). Click (function () {
        var currentfontsize = $ (' html '). CSS (' Font-size ');
        var currentfontsizenum = parsefloat (Currentfontsize, ten);
    
        var newfontsize = currentfontsizenum*0.8;
        $ (' HTML '). CSS (' font-size ', newfontsize);
        return false;
    });
    
    Reset Font Size
    $ (". Resetfont"). Click (function () {
    $ (' HTML '). CSS (' font-size ', originalfontsize);
  });
});

3 Open a link in a new window

Using this jQuery code, any link that the user clicks on your site will open in a new window. As follows:

$ (document). Ready (function () {
    //select all anchor tags, that have http in the href
    //and apply the Target=_blank
  $ ("a[href^= ' http ')"). attr (' target ', ' _blank ');
};

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.