Javascript设置输入字段的值

red*_*cta 8 javascript html5 input setattribute

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

<input style="display: none" type="text" name="geo_poi" value="" id="geofeld" />
Run Code Online (Sandbox Code Playgroud)

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

document.getElementById("geofeld").value = geo_poi;
Run Code Online (Sandbox Code Playgroud)

这总是奏效的.也许新浏览器不再支持上面的方法了.

red*_*cta 19

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

document.getElementById("geofeld").setAttribute("value", geo_poi);
Run Code Online (Sandbox Code Playgroud)