问题
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