JS Common functions Summary (not regularly updated)

Source: Internet
Author: User

1. Compress the picture proportionally

function Setimgsize () {varoutbox_w=imgbox.width (), Outbox_h=imgbox.height (); Imgbox.find ('img'). Each (function (index, EL) {varobj=$ ( This), Objh=obj.height (), OBJW=obj.width (); if((OBJH/OBJW) > (outbox_h/outbox_w)) {obj.css ({height:outbox_h+"px", Width: ((objw/OBJH) *outbox_h) +"px", MarginLeft: ((Outbox_w-((OBJW/OBJH) *outbox_h))/2)+"px"}); }Else{obj.css ({width:outbox_w+"px", Height: ((objh/OBJW) *outbox_w) +"px", MarginTop: ((Outbox_h-((OBJH/OBJW) *outbox_w))/2)+"px"             }); }   });
}

2. Parse the string parameters on the URL:

function getquerystring (parm) {    var reg = new RegExp ("(^|&)" + parm + "= ([^&]*] (&|$)", "I");    var r = window.location.search.substr (1). Match (reg);    if (r! = null) return unescape (r[2]);     return null;}    

Note: the Unescape () function (finds a sequence of characters in the form of%xx and%uxxxx (x for hexadecimal digits), decodes a sequence of characters with Unicode characters \u00xx and \uxxxx, and corresponds to escape () encoding), ECM Ascript V3 has removed the unescape () function from the standard and opposes its use, so it should be replaced with decodeURI () and decodeURIComponent ().

Note: Even if the value of the & connector, there is no relationship, can be encodeuricomponent transcoding into the form of%26, and the browser automatically splicing does not conflict, remember decodeURIComponent () decoding is good.

3, the common JS check

3.1 Mobile phone number check

/^ (0| | 17951)? ([0-9]|  the [012356789]|  - [678]|  - [0-9]|  - [up]) [0-9] {8}$/

3.2 Kanji Check

/^[a-za-z\u4e00-\u9fa5]+$/

JS Common functions Summary (not regularly updated)

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.