如何使用javascript设置文本框的值 [英] how do i set value of a textbox using javascript

查看:124
本文介绍了如何使用javascript设置文本框的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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.

推荐答案

您需要一个小写的和复数元素

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

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

您需要 [0] 才能获得列表中的第一个元素。名称不必像ids那样是唯一的。

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

这篇关于如何使用javascript设置文本框的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆