Javascript setProperty不是函数(…)
当我使用Javascript setProperty不是函数(…),javascript,gwt,Javascript,Gwt,当我使用 $wnd.document.getElementById('id'); 它工作成功,我得到了元素。但是,当我尝试这样设置属性时: $wnd.document.getElementById('id').setProperty("Property","value"); 这给我带来了错误: 未捕获的TypeError:$wnd.document.getElementById(…)。setProperty为 不是一个函数(…) 我的代码中有什么错误可以链接?看起来您是在JSNI方法中执行
$wnd.document.getElementById('id');
它工作成功,我得到了元素。但是,当我尝试这样设置属性时:
$wnd.document.getElementById('id').setProperty("Property","value");
这给我带来了错误:
未捕获的TypeError:$wnd.document.getElementById(…)。setProperty为
不是一个函数(…)
我的代码中有什么错误可以链接?看起来您是在JSNI方法中执行此代码,这意味着它是Javascript。方法setProperty
仅适用于javascript样式元素,与GWT方法setPropertyString()
或类似方法无关
因此:
elem =$wnd.document.getElementById('id');
elem[property] = value;
等于:
$wnd.document.getElementById('id').setAttribute("property","value");
setProperty
适用于以下样式属性:
$wnd.document.getElementById('id').style.setProperty(“颜色”、“蓝色”)
我可以这样设置属性:elem=$wnd.document.getElementById('id');元素[属性]=值代码>但是我想知道,这个路径不起作用的原因是什么:$wnd.document.getElementById('id').setProperty(“属性”,“值”)代码>在IE中,我捕获到异常对象不支持属性或方法“setProperty”