首页 > 解决方案 > 未捕获的 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;
}

我认为得到这个是因为值是字符串。我该如何解决这个问题?

标签: javascriptjquery

解决方案


推荐阅读