javascript - setProperty 不是函数(...)

标签 javascript gwt

当我使用

$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/

相关文章:

javascript - 在 Create React App 中为节点模块添加自定义 Typescript 类型声明

java - GwtUpload Servlet 错误

gwt - GWT 有段落小部件吗?

java - GXT FileUploadField 的按键事件

java - 更改 smartGWT 中的过滤标准

java - SmartGWT - 动态更新ListGridRecord

javascript - 使用 MeteorJS 将包装在 Fiber 中的服务器端数据返回到客户端调用

javascript - 最小 Angular2 应用程序接收未处理的 Promise SystemJS 错误

javascript - Mongoose 批量保存/异步更新每次只更新一些文档

javascript - 动态添加的 Angular2 组件不会渲染,但静态添加的组件会渲染