Dijit.Form.Textarea 的设置值
我有一个 dijit 对话框,其中包含我想要自动填充的表单。我可以让对话框显示其中包含表单,但我无法设置表单内文本区域的值。这是存放 html 的 div。
<div dojoType="dijit.Dialog" id="formDialog" title="Form Dialog" >
<table>
<tr>
<td>
<label for="desc">
Description:
</label>
</td>
<td>
<textarea id="desc" name="desc" dojoType="dijit.form.Textarea" style="width:200px;"></textarea>
节省 关闭
来很好地显示它
我可以通过执行var formDlg = dijit.byId("formDialog"); formDlg.show();
但我遇到的问题是设置名为“desc”的文本区域的值。我已经尝试了多种方法,但我知道我需要这样做
var test = dijit.byId("desc");
,但是如果我设置了测试的任何属性,例如
test.value = "foo";
test.textContent = "foo";
test.innerHTML = "foo";
test.srcNodeRef = "foo";
该值永远不会保存并显示在文本区域内。这样做有什么技巧吗?任何帮助都会很棒。谢谢
I have a dijit dialog that contains a form that I want to auto-populate. I can get the dialog to display with the form in it, but I have been unable to set the value of a text area within the form. Here is the div that houses the html.
<div dojoType="dijit.Dialog" id="formDialog" title="Form Dialog" >
<table>
<tr>
<td>
<label for="desc">
Description:
</label>
</td>
<td>
<textarea id="desc" name="desc" dojoType="dijit.form.Textarea" style="width:200px;"></textarea>
SAVE
CLOSE
I can get this to display just fine by doing
var formDlg = dijit.byId("formDialog");
formDlg.show();
But the issue I have is setting the value of the textarea called "desc". I have tried multiple things, but I know I need to
var test = dijit.byId("desc");
but if I set any property of test, such as
test.value = "foo";
test.textContent = "foo";
test.innerHTML = "foo";
test.srcNodeRef = "foo";
The value is never saved and displayed inside the textarea. Is there a trick to doing this? Any help would be great. Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
..我想应该可以解决这个问题。 Dojo 中的大多数小部件都使用
set
方法(以前称为attr
)来设置属性值,而不是像您尝试的那样直接操作它们。您还可以通过传递一个对象来一次性设置多个属性:..should do the trick, I think. Most widgets in Dojo use the
set
method (formerlyattr
) to set property values, instead of manipulating them directly like you've tried to do. You can also set multiple properties in one go by passing an object:由于某些原因,
dijit.byId("txtAreaMytextarea").set("value", "somevalue")
不适用于TextArea
,但当您使用 Dojo 1.6 并使用dijit.form.SimpleTextarea
作为TextArea
。函数setValue("")
也不起作用。如果您遇到这种情况,请尝试使用
dojo.byId
而不是dijit.byId
并通过执行以下操作来设置值For some reason,
dijit.byId("txtAreaMytextarea").set("value", "somevalue")
does not work withTextArea
but works with other dijit types when you use Dojo 1.6 and usedijit.form.SimpleTextarea
asTextArea
. The functionsetValue("")
also doesn't work.If this happens to you, try using
dojo.byId
instead ofdijit.byId
and just setting value by doing