Let's take a look at my code. Just embed the code in the paging file
Example One
Using regular expressions to get
Copy Code code as follows:
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 "";
}
Call method
Copy Code code as follows:
document.getElementById ("User"). Value = Getquerystr ("user");
document.getElementById ("password"). Value = Getquerystr ("password");
document.getElementById ("Sysno"). Value = Getquerystr ("Sysno");
Case II
Use the Split function to cut an array by parameters
Copy Code code as follows:
<script>
Urlinfo=window.location.href; Gets the URL of the current page
len=urlinfo.length;//gets the length of the URL
Offset=urlinfo.indexof ("?"); /sets the position at which the parameter string starts
NEWSIDINFO=URLINFO.SUBSTR (Offset,len)//Fetch parameter string This will get a string like "id=1"
Newsids=newsidinfo.split ("=");//To split the obtained argument string by "="
newsid=newsids[1];//get the parameter value
Alert ("The parameter value you want to pass is" +newsid);
</script>
But remember that this method is only useful for URLs that contain parameters, and if the other side uses the Post method to pass parameters, the URL will not contain any parameters, so this technique is useful only for get methods or URLs that specify parameters.
Let's look at a complete example
Aa.htm is the parametric input infiltration interface
Bb.htm is the parameter receive processing interface
Aa.htm
Copy Code code as follows:
<body>
<script>
function Submit ()
{
var input1 = document.getElementById ("inputID");
window.open ("bb.htm?inputstr=" + input1.value);//Incoming parameters
}
</script>
<input type = "text" id = "inputID" >
<input type = "button" onclick = "submit ()" VALUE = "Submit" >
</body>
Bb.htm:
<script>
Methods of obtaining parameters
var request =
{
Querystring:function (Val)
{
var uri = Window.location.search;
var re = new RegExp ("+val+" = ([^&?] *) "," IG ");
Return (Uri.match (re))? ( Uri.match (re) [0].substr (Val.leng th+1)): null);
}
}
</script>
<body>
<script>
Call method Get parameter
var RT = Request. QueryString ("Inputstr");
alert (RT);
</script>
</body>
Bb.htm
Copy Code code as follows:
<title>test</title>
<meta http-equiv= "Content-type" content= "text/html; charset=gb2312 ">
<script language= "JavaScript" >
<!--
var request = {
Querystring:function (val) {
var uri = Window.location.search;
var re = new RegExp ("+val+" = ([^&?] *) "," IG ");
Return (Uri.match (re))? ( Uri.match (re) [0].substr (Val.leng th+1)): null);
}
}
var a = Request. QueryString ("a");
var B = Request. QueryString ("B");
var c = Request. QueryString ("C");
if ((a!= null)) {a=a} else{a= "parameter a Null"}
if ((b!= null)) {b=b} else{b= "parameter B Empty"}
if ((c!= null)) {c=c} else{c= "parameter C Null"}
Document.writeln ("parameter A:" + a);
Document.writeln ("<br> parameter B:" + B);
Document.writeln ("<br> parameter C:" + C);
-->
</SCRIPT>
<body>
<form name= "Form1" action= "?" >
Please input parameter value:<br>
<script language= "JavaScript" >
Document.writeln ("A:<input type= ' text ' name= ' A ' value= '" "+a+" ' ><br> ");
Document.writeln ("B:<input type= ' text ' name= ' B ' value= '" "+b+" ' ><br> ");
Document.writeln ("C:<input type= ' text ' name= ' C ' value= '" "+c+" ' ><br> ");
</SCRIPT>
<input type= "Submit" name= "Submit" value= "Submission parameter view effect" >
</form>
</body>