change value of text using getElementsByName

核能气质少年 提交于 2019-12-08 17:45:17

问题


I have firstName text that I want to change his value but it not work -

<input type="text" name="firstName" />
<script LANGUAGE="JavaScript" TYPE="text/javascript">
      document.getElementsByName("firstName").[0].value = "New Value " ;
</script>

How can I change this value ?


回答1:


That's not syntactically valid JS. Remove the extra .:

//                                    ↓↓
document.getElementsByName("firstName")[0].value = "New Value " ;
//                                    ↑↑

and the rest will work.



来源:https://stackoverflow.com/questions/11851682/change-value-of-text-using-getelementsbyname

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!