我不能fingure爲什麼這個代碼不工作:解析URL字符串成JSON不斷重新調整空對象
$(document).ready(function() {
$(".alertDeleteButton").click(function(e) {
var str = $(this).attr("href");
alert(str);
var obj = str.split("&").reduce(function(prev, curr, i, arr) {
var p = curr.split("=");
prev[decodeURIComponent(p[0])] = decodeURIComponent(p[1]);
return prev;
}, {});
alert(obj);
e.preventDefault();
});
});
所有我想要做的,就是用字符串在用戶按下鏈接時創建一個json對象。
{「userdeleteid」:「55」,「dayid」:「55」}。等...
我已經搜索並找到了3種不同的方式來做到這一點,他們都給我[對象對象]的結果。
I wanted to implement this,但它似乎只在瀏覽器中查看URL,我希望它通過(this).attr(「href」)查看鏈接的值;
'警報()'輸出字符串,因此需要將對象轉換爲字符串。您應該使用Firebug的控制檯或瀏覽器的等效工具進行調試。 – 2013-02-28 16:38:44