Dijit.Form.Textarea 的设置值

发布于 2024-10-19 11:22:07 字数 1074 浏览 0 评论 0原文

我有一个 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

我爱人 2024-10-26 11:22:07
var test = dijit.byId("desc");
test.set("value", "foo");

..我想应该可以解决这个问题。 Dojo 中的大多数小部件都使用 set 方法(以前称为 attr)来设置属性值,而不是像您尝试的那样直接操作它们。您还可以通过传递一个对象来一次性设置多个属性:

var test = dijit.byId("desc");
test.set({"value": "foo", "name": "someName"});
var test = dijit.byId("desc");
test.set("value", "foo");

..should do the trick, I think. Most widgets in Dojo use the set method (formerly attr) 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:

var test = dijit.byId("desc");
test.set({"value": "foo", "name": "someName"});
挽袖吟 2024-10-26 11:22:07

由于某些原因,dijit.byId("txtAreaMytextarea").set("value", "somevalue") 不适用于 TextArea,但当您使用 Dojo 1.6 并使用 dijit.form.SimpleTextarea 作为 TextArea。函数 setValue("") 也不起作用。

如果您遇到这种情况,请尝试使用 dojo.byId 而不是 dijit.byId 并通过执行以下操作来设置值

dojo.byId("txtAreaMytextarea").value = "somevalue";

For some reason, dijit.byId("txtAreaMytextarea").set("value", "somevalue") does not work with TextArea but works with other dijit types when you use Dojo 1.6 and use dijit.form.SimpleTextarea as TextArea. The function setValue("") also doesn't work.

If this happens to you, try using dojo.byId instead of dijit.byId and just setting value by doing

dojo.byId("txtAreaMytextarea").value = "somevalue";
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文