Parse js: how to obtain the parameter values in the current url and copy them to input _ basics-js tutorial

Source: Internet
Author: User
This article describes how to obtain the parameter values in the current url in js and copy them to the input file. For more information, see The Code is as follows:


Function getObject (objectId ){
If (document. getElementById & document. getElementById (objectId )){
Return document. getElementById (objectId );
} Else if (document. all & document. all (objectId )){
Return document. all (objectId );
} Else if (document. layers & document. layers [objectId]) {
Return document. layers [objectId];
} Else {
Return false;
}
}
Function get (p ){
// Var url = location. search;
Var url = document. URL. toString ();
Var tmpStr = p + "= ";
Var tmp_reg = eval ("/[\? &] "+ TmpStr +"/I ");
If (url. search (tmp_reg) =-1) return null;
Else {
Var a = url. split (/[\? &]/);
For (var I = 0; I if (a [I]. search (eval ("/^" + tmpStr + "/I "))! =-1) return a [I]. substring (tmpStr. length );
}
}
Window. onload = function (){

GetObject ("key"). value = get ("k ");
// The key is the name in the input, and the received value is the k parameter in the browser.
// K is the parameter name in the browser
}


Put the above Code at the bottom of the html page.
Related Article

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.