【发布时间】:2021-05-01 12:43:16
【问题描述】:
说明:
我尝试动态获取 HTML-Object 的值。所以我在 Object 上写了一个原型函数 select。它在控制台上工作,但不在脚本中。一个 jquery 属性有一些反对它的东西。
错误:
Uncaught TypeError: can't assign to property "guid" on "innerText": not an object
相关对象的输出:
Object { 0: th, 1: th, 2: th, 3: th, 4: th, 5: th, length: 6, prevObject: {…} }
对象上的功能选择:
Object.prototype.select = function(what)
{
return this.map(function() {
return this[what];
}).get();
}
来电:
label.select('innerText')
这是一个已知的错误吗?有解决方法吗?调试器只是与 jquery 中的一个点有关:
S.find.matchesSelector(re,i),n.guid||(n.guid=S.guid++)
已经解决了:
function getData(data)
{
return $(data).map(function() {
return this.value;
}).get();
}
【问题讨论】:
-
嗨!请使用 minimal reproducible example 来更新您的问题,以展示问题,最好是使用 Stack Snippets(
[<>]工具栏按钮)的 runnable 问题; here's how to do one. -
你试过
obj[what]吗?它返回保存在哪个变量中的属性的 obj 值,如果不存在则返回 undefined
标签: javascript jquery object html-object