$("#btn").on("click", function (event) {
//console.log($(this).browserParams())
console.log($.browserParams())
})
//局部封装:
//调用方式:$(this).browserParams()
$.fn.browserParams = function () {
var urlObj = window.location.href.split("?")
if (urlObj.length > 1) {
var data = {}
urlObj[1].split("&").forEach((element) => {
let result = element.split("=")
data[result[0]] = result[1]
})
return data
} else {
return {}
}
}
//全局封装
//调用方式:$.browserParams()
$.extend({
browserParams: function () {
var urlParams = window.location.search.substr(1).split("&")
var data = {}
urlParams.forEach(function (param) {
var paramSplit = param.split("=")
data[paramSplit[0]] = decodeURIComponent(paramSplit[1]) || ""
})
return data
},
})