Car*_*ñiz 0 javascript javascript-events
我想使用javascript向文本字段添加一串文本,但我不想使用onClick或onLoad事件来执行此操作.
我只是想在浏览器读取它时立即执行javascript,并且javascript将在html的主体内.
文本字段就像
<form action="" method="post" name="formname" id="user-registration-form">
<input type="text" name="edit-form" id="edit-form" />
</form>
Run Code Online (Sandbox Code Playgroud)
我尝试过类似的东西,但它不起作用:
<script type="text/javascript"> edit-form.value="the new value"; </script>
Run Code Online (Sandbox Code Playgroud)
我怎样才能做到这一点?
你试过这个吗? document.getElementById()
<script type="text/javascript"> document.getElementById("edit-mail").value="the new value"; </script>
Run Code Online (Sandbox Code Playgroud)
假设编辑邮件是您的文本框ID