gpt4 book ai didi

JavaScript 错误 : Cannot Convert Object to Primitive Value

转载 作者:数据小太阳 更新时间:2023-10-29 03:50:11 25 4
gpt4 key购买 nike

我在使用以下 javascript 代码时收到此错误:

function tempTest(evt) {
alert(evt.currentTarget.id);
ct = document.getElementById(evt.currentTarget.id);
rslt = document.getElementById('rslt');
var props;
for (var prop in ct) {
if (ct.hasOwnProperty(prop)) {
propVal = ct[prop];
var propDat = prop + ' = ' + propVal;
props += propDat + '<br/>';
}
}
rslt.innerHTML = props;
}

这个让我很困惑。有什么想法吗?

最佳答案

并非 HTML 元素的所有属性都是原语。例如,parent、childs 等也是 HTML 元素。您不能只将它们用作字符串或数字。
您需要在其中添加条件并相应地使用该属性。

关于JavaScript 错误 : Cannot Convert Object to Primitive Value,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6667291/

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