setProperty 不是函数(...)
setProperty is not a function(...)
当我使用
$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
适用于这样的样式属性:
$wnd.document.getElementById('id').style.setProperty("color","blue");
当我使用
$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
适用于这样的样式属性:
$wnd.document.getElementById('id').style.setProperty("color","blue");