Javascript设置输入字段的值 [英] Javascript set value of an input field

查看:112
本文介绍了Javascript设置输入字段的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

因为我无法使用type = text设置输入字段的值。
之前,我总是使用这样的东西:

Since while I cannot set the value of an input field with type=text. Before, I always used something like this:

<input style="display: none" type="text" name="geo_poi" value="" id="geofeld" />

然后,在JavaScript中我添加了包含如下行的代码:

Then, in JavaScript i added code containing a line like this:

document.getElementById("geofeld").value = geo_poi;

这总是有用的。也许新的浏览器不再支持上面的方法了。

This always worked. Maybe the new browsers don't want to support the method above anymore.

推荐答案

因此使用以下方法设置属性工作正常。

So using the following method for setting attributes worked fine.

document.getElementById("geofeld").setAttribute("value", geo_poi);

这篇关于Javascript设置输入字段的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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