如何使用 javascript 设置文本框的值

发布于 2024-10-09 01:13:19 字数 188 浏览 0 评论 0原文

我正在尝试从查询字符串获取一个值并将该值分配到文本框中。 我能够从查询字符串中获取值,但无法将其分配给文本框。

document.getElementByName('Contact0Email').Value = email;

尝试了上面的代码,但似乎不起作用。尽管电子邮件警报给出了正确的值。

I am trying to get a value fro query string and assign that value into a textbox.
I am able to get the value from query string but unable to assign it to textbox.

document.getElementByName('Contact0Email').Value = email;

Tried the above code but doesn't seem to be working. Though the alert of email gives the right value.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

野却迷人 2024-10-16 01:13:19

您需要一个小写的 value 和一个复数的 Elements

document.getElementsByName('Contact0Email')[0].value = email;

您需要 [0] 来获取列表中的第一个元素。名称不必像 id 那样是唯一的。

You need a lower-case value and a plural Elements:

document.getElementsByName('Contact0Email')[0].value = email;

You need the [0] to get the first element in the list. Names don't have to be unique like ids.

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