gpt4 book ai didi

javascript - 语法错误: missing ) after argument list in javascript function with json response

转载 作者:行者123 更新时间:2023-12-01 03:53:17 25 4
gpt4 key购买 nike

这看起来可能是重复的,但就我而言,它有点不同。我有以下代码:

function stateList() {              
function parseStateList(response){
var stateTable= "<table><tr><td style='width: 500px; color: blue;'>Folder name (state)</td></tr>";
console.log(response);
statelist=response["States"];
console.log(statelist);
for (var i in statelist) {
a = statelist[i];
var index = Object.keys(statelist).indexOf(i)
console.log("i="+index);
console.log(statelist[i]);
stateTable+="<tr><td style='width: 500px;'><button id=\""+index+"\" onclick=\"GetSavedState("+a+",parseSavedState)\">" + a + "</button></td></tr>";
//document.getElementById(index).onclick = function(){GetSavedState(a,parseSavedState);};
}
stateTable+="</table>";
document.getElementById('state_output').innerHTML = stateTable;
}

GetStateList(parseStateList);
}

我收到此错误 SyntaxError: Missing ) after argument list

最佳答案

错误不在您在问题中输入的代码中。我制作了一个虚拟 GetStateList 函数,并且该代码段工作正常。例如,这表明错误存在于从 GetStateList 获得的响应结构中。

PD:我冒昧地引用了 GetSavedState 的第一个参数,因为您将其作为变量传递,而 a 是一个字符串。

function GetStateList(callback) {
callback(
{
"States":{
"CA":"California",
"FL":"Florida"
}
});
}
function GetSavedState(stateusps, callback) {
callback(stateusps);
}
function parseSavedState(savedState) {
console.log(savedState);
}

function stateList() {
function parseStateList(response) {
var stateTable = "<table><tr><td style='width: 500px; color: blue;'>Folder name (state)</td></tr>";
console.log(response);
statelist = response["States"];
console.log(statelist);

for (var i in statelist) {
a = statelist[i];
var index = Object.keys(statelist).indexOf(i)
console.log("i=" + index);
console.log(statelist[i]);
stateTable += "<tr><td style='width: 500px;'>";
stateTable += "<button id=\"" + index + "\" onclick=\"GetSavedState('" + a + "',parseSavedState)\">" + a + "</button>";
stateTable += "</td></tr>";
}

stateTable += "</table>";
document.getElementById('state_output').innerHTML = stateTable;
}

GetStateList(parseStateList);
}

stateList();
<div id="state_output"></div>

这并不能回答您的错误,它只是证明它不在您认为的位置。

关于javascript - 语法错误: missing ) after argument list in javascript function with json response,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42997588/

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