SoFunction
Updated on 2025-03-09

Use js to get the summary of the method of QueryString


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http:///TR/xhtml1/DTD/">
<html xmlns="http:///1999/xhtml">
<head>
<meta content="text/html; charset=gb2312" http-equiv="Content-Type" />
<title>QueryString Get Demo Code </title>
<script type="text/javascript">
//Get the array of QueryString
function getQueryString(){
var result = (new RegExp("[\?\&][^\?\&]+=[^\?\&]+","g"));
for(var i = 0; i < ; i++){
result[i] = result[i].substring(1);
}
return result;
}
//Get the value according to the QueryString parameter name
function getQueryStringByName(name){
var result = (new RegExp("[\?\&]" + name+ "=([^\&]+)","i"));
if(result == null || < 1){
return "";
}
return result[1];
}
//Get the value according to the QueryString parameter index
function getQueryStringByIndex(index){
if(index == null){
return "";
}
var queryStringList = getQueryString();
if (index >= ){
return "";
}
var result = queryStringList[index];
var startIndex = ("=") + 1;
result = (startIndex);
return result;
}
//Binding the action performed when the control is highlighted and selected, click "Enter"
//control: The control to bind the event
//func: The method to be executed
function bindEnterEvent(control, func){
= function(){
if ( == 13){
func();
}
}
}
//Get the value based on the entered QueryString name
function getByName(){
var name = ("txtQueryStringName").value;
("txtResult").innerHTML = getQueryStringByName(name);
}
//Get the value based on the index of the input QueryString
function getByIndex(){
var index = ("txtQueryStringIndex").value;
("txtResult").innerHTML = getQueryStringByIndex(index);
}
</script>
</head>
<body>
<div>
<span>QueryString : </span><span ></span>
</div>
<div>
<span>QueryString's name :&nbsp;</span>
<input name="txtQueryStringName" type="text" />
<input name="btnGetByName" type="button" value="get" onclick="getByName()" />
</div>
<div>
<span>QueryString's index : </span>
<input name="txtQueryStringIndex" type="text" />
<input name="btnGetByIndex" type="button" value="get" onclick="getByIndex()" />
</div>
<div>
<span>Result:</span><span></span>
</div>
<!--Operation performed when page loads-->
<script type="text/javascript">
//Show all QueryStrings
("queryString").innerHTML = getQueryString();
//Bind the carriage return event for txtQueryStringName
bindEnterEvent(txtQueryStringName, getByName);
//Bind the carriage return event for txtQueryStringIndex
bindEnterEvent(txtQueryStringIndex, getByIndex);
</script>
</body>
</html>