Several jquery code snippets that can be used directly

Source: Internet
Author: User

jquery offers a number of ways to create interactive websites, many of the available code on foreign sites, and a few good ones to share.

Pre-load Picture

 (function   ($) { var  cache = [];  //  Arguments is image paths relative to  The current page.  $.preloadimages = function   () { var  args_len = Arguments.length;  for  (var  i = Args_len; i--;) { var  cacheimage = document.createelement (' img ' 

Source

Adaptive on mobile devices

var scr = document.createelement (' script '); Scr.setattribute (' src ', ' https://ajax.googleapis.com/ Ajax/libs/jquery/1.5.2/jquery.min.js 'function() {    $ (' div '). attr (' class ', '). attr (' id ', '). css ({        ' margin ': 0,        ' padding ': 0,        ' width ': ' 100% ',        ' Clear ': ' Both '    } ;

Source

Back to Top

// Back to Top$ (document). Ready (function() {  $ ('. Top '). Click (function() {      $ (document). ScrollTo (0,500);   } ); // Create a link defined with the class top<a href= "#" class= "Top" >back to Top</a>

Source

Auto Fill selection box

$ (function() {$ ("Select#ctljob"). Change (function() {$.getjson ("/select.php", {ID: $ (thisfunction(j) {var options = ';  for (var i = 0; i < j.length; i+++ = "+ J[i].optiondisplay +";} $ ("Select#ctlperson"). HTML (options); })})

Source

Prevent forms from being submitted multiple times

$ (document). Ready (function() {  $(' form '). Submit (function() {    if(typeofJquery.data ( This, "disabledonsubmit") = = ' undefined ') {Jquery.data ( This, "Disabledonsubmit", {submited:true }); $(' Input[type=submit], Input[type=button] ', This). each (function() {        $( This). attr ("Disabled", "disabled");      }); return true; }    Else    {      return false; }  });});

Source

Several jquery code snippets that can be used directly

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.