我环顾四周寻找解决方案,但我可能只是错过了一些非常明显的东西,因为它们不能解决我的问题。我完全不是JS,只是一个免责声明。未捕获的ReferenceError:x没有在HTMLTableRowElement.onclick中定义
我有一个ASP项目,JavaScript调用了一些C#代码。我用这个开始我的代码:
window.onload = function() {
LiveSearch();
getCredentials();
getAllUsers();
getIsAdmin();
};
所有这些函数都可以正常工作。但感兴趣的是getAllUsers(),因为它通过AJAX调用联系后端以获取一些数据来填充表。
function getAllUsers() {
var result_body = "";
$.ajax({
type: 'GET',
url: '/Home/GetAllUsers',
dataType: 'json',
cache: false,
contentType: 'application/json; charset=utf-8',
data: JSON.stringify(""),
success: function (users) {
PushToScope("users", users);
var dict = scope[2];
if (dict.key.length > 0) {
for (var key in dict.value) {
result_body += '<tr onclick="getClickedUserObject(' + dict["value"][key].Initials + ')\">';
result_body += '<td class=\"col-xs-4\">' + dict["value"][key].Name + '</td>'
result_body += '<td class=\"col-xs-4\">' + dict["value"][key].Title + '</td>'
result_body += '<td class=\"col-xs-4\">' + dict["value"][key].Department + '</td>'
result_body += '<td style=\"display: none\">' + dict["value"][key].PrivatePhone + '</td>'
result_body += '<td style=\"display: none\">' + dict["value"][key].WorkEmail + '</td>'
result_body += '<td style=\"display: none\">' + dict["value"][key].WorkPhoneLandline + '</td>'
result_body += '<td style=\"display: none\">' + dict["value"][key].WorkPhoneMobile + '</td>'
result_body += '</tr>';
}
} else {
result_body += '<tr>';
result_body += '<td style=\"col-xs-12\"><b>No Data. Try again, or Contact IT Support.</b></td>';
result_body += '</tr>';
}
$('#result-table').html(result_body);
}
});
}
就像我说的,上面的作品,但是当我在点击表格中的元素就会出现问题等等。 “getClickedUserObject()”的:
function getClickedUserObject(lettercode) {
if (lettercode != undefined) {
var users = scope[2];
var user = users["value"][lettercode];
$('#result-title').html(user.Title);
$('#result-name').html(user.Name);
$('#result-department').html(user.Department);
$('#result-email').html('<a href=\"mailto:' + user.WorkEmail + '\">' + work.WorkEmail + '</a>');
$('#result-work-mobile').html(user.WorkPhoneMobile);
$('#result-work-landline').html(user.WorkPhoneLandline);
$('#result-private-mobile').html(user.PrivatePhone);
if (lettercode == scope[0]) {
$("#HidePrivate").show();
$("#HidePrivate").disabled = false;
$("#HidePrivate").checked = user.HiddenPrivatePhone;
} else {
$("#HidePrivate").hide();
$("#HidePrivate").disabled = true;
}
}
return false;
}
此功能不闪光,而不是我得到错误的标题,说什么lettercode我就从点击未定义排弄。这是奇怪的我,因为看在谷歌Chrome检查我看到这一点:
那么是什么原因?就像我说的,我不是JS Wiz,所以如果我错过了非常明显的东西,请和我一起裸露。
您尝试访问的对象不存在的属性,没有工作的例子,我不能relly帮助很大,它可能是'用户之一*'。你可以注释掉整个区块,然后逐行删除评论,看看它在哪一点破裂 – maurycy
医师已经指出了这个问题。 – OmniOwl