当我使用
$wnd.document.getElementById('id');
它运行成功,我得到了元素。但是,当我尝试像这样设置 property
时:
$wnd.document.getElementById('id').setProperty("Property","value");
它给我带来了错误:
Uncaught TypeError: $wnd.document.getElementById(...).setProperty is not a function(…)
我的代码有什么错误可以链接?
最佳答案
看起来您正在 JSNI 方法中执行此代码,这意味着它是 Javascript。 setProperty
方法仅适用于 javascript style 元素,与 GWT 方法 setPropertyString()
或类似方法无关。
所以这样:
elem =$wnd.document.getElementById('id');
elem[property] = value;
等于:
$wnd.document.getElementById('id').setAttribute("property","value");
setProperty
将适用于这样的 Style 属性:
$wnd.document.getElementById('id').style.setProperty("color","blue");
关于javascript - setProperty 不是函数(...),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37387708/