javascript - 未捕获的 ReferenceError:值未在 HTMLAnchorElement.onclick 中定义
问题描述
我想调用一个函数时收到 Uncaught ReferenceError 错误。我想通过这个函数传递一些价值。函数声明是另一面。
这是我的 jQuery 代码,我将数据从 json 数据填充到表中。请注意,在这里用户名我有像 rifat 这样的值,当我单击或调用 onget(rifat) 时,我得到了 Uncaught ReferenceError: rifat is not defined
for (let i = 0; i < result.data.resultSet.length; i++) {
let tableallrowdata = {
username: result.data.resultSet[i].username,
firstname: result.data.resultSet[i].firstname,
usertype: result.data.resultSet[i].usertype
};
console.log(tableallrowdata);
let tableItem = "<tr><td>" + result.data.resultSet[i].username + "</td>";
tableItem = tableItem + '<td>' + result.data.resultSet[i].firstname + '</td>';
tableItem = tableItem + '<td>' + result.data.resultSet[i].lastname + '</td>';
tableItem = tableItem + '<td>' + result.data.resultSet[i].email + '</td>';
tableItem = tableItem + '<td>' + result.data.resultSet[i].usertype + '</td>';
tableItem = tableItem + '<td ><a onClick="onGet(' + tableallrowdata.username + ', ' + tableallrowdata.firstname + ', ' + tableallrowdata.usertype + ')"><img src="/images/Common UI Assets/Icon-16.png" ></img></a><a><img src="/images/Common UI Assets/Icon-16 _Delete.png" style="padding-left:20px;" /></a></td></tr>';
newTableData += tableItem;
}
这里是函数体。我对其进行了控制台,但在控制到这里之前我得到了这个错误。这是我的函数代码
this.onGet = function (username, firstname, usertype) {
console.log(username);
console.log(firstname);
console.log(usertype);
//var url = "./UserUpdate?name=" + username + "&firstname=" + firstname + "&usertype=" + usertype;
//window.location.href = url;
}
我认为得到这个是因为值是字符串。我该如何解决这个问题?
解决方案
推荐阅读
- android - 无法解析符号 AppCompatActivity,无法解析符号 ContextCompat
- c++ - C++ 访问外部类的静态字段 [获取错误 LNK2001]
- angular - Angular - 如何 MarkForCheck() ngfor 模板中的单个项目
- javascript - Map.On / Map.off MapboxGL JS
- regex - 用于替换除空白和指定目标之外的所有内容的正则表达式 Scala
- c# - 转换日期时间时,字符串未被识别为有效的日期时间
- python - 打开一个文本文件并创建一个字典变量
- ios - 无法在表视图内的集合视图上正确填充数组数据
- excel - 如何在数据库中上传时处理excel中的空白值还希望在excel中下载表而不在jsp中指定列名
- c++ - 没有初始化器的 constexpr 静态数据成员