gpt4 book ai didi

javascript - 如何将 $.extend() 与变量一起使用

转载 作者:行者123 更新时间:2023-11-28 12:43:16 24 4
gpt4 key购买 nike

我正在尝试制作一个脚本来使用 window.location.hash 中的多个值,但我在使用 jquery 的 $.extend() 函数时遇到问题

我尝试了两种方法,但都没有成功。

var MultiHash = {
params: {},

getHash: function () {
var hashString = document.location.hash.replace('#', '').split('&');

for (var i=0; i < hashString.length; i++) {
var key = hashString[i].split('=')[0];
var value = decodeURIComponent(hashString[i].split('=')[1]);

// First way
var a = {key: value};

// Second way
var a = {};
a[key] = value;

$.extend(params, a);
}

return params;
},

...
}

有人发现这个问题了吗?

最佳答案

首先你应该写:

 $.extend(this.params, a); or you cant access param

可能还有其他问题。

编辑

在我看来,返回 a 而不是 this.params 是有意义的。

$.extend(a,this.params);

return a

关于javascript - 如何将 $.extend() 与变量一起使用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10655900/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com