Detailed example of how Javascript uses functions and regular expressions to obtain static page parameter values

伊谢尔伦
Release: 2017-07-26 17:24:26
Original
1553 people have browsed it

To obtain the passed values of HTML static page parameters, you can use the split function to cut into arrays by parameters and use regular expressions to obtain them. The specific implementation is as follows

Example 1Use regular expressions to obtain Get

var LocString = String(window.document.location.href); function getQueryStr(str) { var rs = new RegExp("(^|)" + str + "=([^&]*)(&|$)", "gi").exec(LocString), tmp; if (tmp = rs) { return tmp[2]; } // parameter cannot be found return ""; }
Copy after login

Call method

document.getElementById("user").value = getQueryStr("user"); document.getElementById("password").value = getQueryStr("password"); document.getElementById("sysno").value = getQueryStr("sysno");
Copy after login

Example 2Use the split function to cut into arrays according to parameters

Copy after login

But be sure to remember that this method is only for files containing The URL of the parameter is useful. If the other party uses the POST method to pass the parameter, the URL will not contain the parameter, so this technique is only useful for the GET method or the URL with specified parameters.

Look at a complete example below
aa.htm is the parameter input and penetration interface
bb.htm is the parameter receiving and processing interface
aa.htm

       
                    bb.htm:            
           
Copy after login

bb.htm

      test         
     
  请输入参数值:
        
     
Copy after login


The above is the detailed content of Detailed example of how Javascript uses functions and regular expressions to obtain static page parameter values. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!