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

JavaScript implements QueryString method to obtain GET parameters_javascript skills

WBOY
Release: 2016-05-16 17:30:21
Original
1110 people have browsed it
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;
});
});
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template