gpt4 book ai didi

javascript - 通过 .value 设置文本字段的值

转载 作者:行者123 更新时间:2023-11-30 11:50:38 25 4
gpt4 key购买 nike

<分区>

我知道这应该是一个非常简单的问题,但我不知道为什么不能将值分配给文本字段?我还通过为输入分配一个 id 来尝试 getElementById,但这也行不通。在过去的 3 小时里,我一直在为此苦苦挣扎。我做错了什么吗?

Javascript 是

  document.form1.hello.value= "123";

HTML 是

    <form name="form1" class="" action="index.html" method="post">
<input type="text" name="hello" value="">
</form>

Uncaught TypeError: Cannot read property 'hello' of undefined 是错误。

完整版是

    <!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
<script type="text/javascript">
document.form1.hello.value= "123";
</script>
</head>
<body>
<form name="form1" class="" action="index.html" method="post">
<input type="text" name="hello" value="">
</form>
</body>
</html>

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com