Home  >  Article  >  Web Front-end  >  JavaScript implements QueryString method to obtain GET parameters_javascript skills

JavaScript implements QueryString method to obtain GET parameters_javascript skills

WBOY
WBOYOriginal
2016-05-16 17:30:211070browse
Copy code The code is as follows:


< select name="select1" id="select-type">





Copy code The code is as follows:

QueryString = {
data: {},
Initial: function () {
var aPairs, aTmp;
var queryString = new String(window.location.search);
queryString = queryString.substr(1, queryString.length); //remove "?"
aPairs = queryString.split("&");
for (var i = 0; i < aPairs.length; i ) {
aTmp = aPairs[i].split("=");
this.data[aTmp[0]] = aTmp[1];
}
},
GetValue: function (key) {
return this.data[key];
}
}

$(function () {
//Initialization
QueryString.Initial();

var type = QueryString.GetValue("type") ;

if (typeof (type) != "undefined") {
$("#select-type").val(type);
}

$( "#select-type").bind("change", function () {
var row = $(this).find("option:selected").val();

// alert(row);
if (row == 1)
location.href = "?type=" row;
if (row == 2)
location.href = "?type= " row;
});
});
Statement:
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