Some JavaScript usage

Source: Internet
Author: User

Recently, I am working on projects for my mentor, and I am also officially studying web. I was wondering how to make something separate.ArticleBut some are my own summary, and some are nice to see others.Code. Therefore, all the "One Pot" methods are put here, and all the new things are posted here to facilitate future queries.

 

1. getparameter in JS

1) Take a parameter

VaR paramter_value = NULL; <br/> function getparameter (paramname) {<br/> If (! Paramter_value) {// The first initialization <br/> paramter_value = new array (); <br/> var paramstr = location. search. substring (1); <br/> var paramarr = paramstr. split ("&"); <br/> var Len = paramarr. length; <br/> var temparr; <br/> for (VAR I = 0; I <Len; I ++) {<br/> temparr = paramarr [I]. split ("="); <br/> paramter_value [temparr [0] = temparr [1]; <br/>}< br/> var paramvalue = paramter_value [paramname]; <br/> If (paramvalue) {<br/> return paramvalue; <br/>}< br/>} 

2) multiple parameters

function getparameter (name) {<br/> var regexs = "[//? &] "+ Name +" = ([^ & #] *) "; <br/> var RegEx = new Regexp (regexs); <br/> var tmpurl = Window. location. href; <br/> var Results = regex.exe C (tmpurl); <br/> If (Results = NULL) <br/> return ""; <br/> else <br/> return results [1]; <br/>}

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.