【发布时间】:2013-04-26 01:42:23
【问题描述】:
嗨,对不起,我是 Javascript 的新手,但我需要知道当我有这种表单时如何重新填充表单字段:
我尝试使用此代码(部分)但它不起作用,文件名是'testjavascript.html'
<head>
<script language="javascript" type="text/javascript">
function updateUsername(){
var first = document.getElementById("first").value;
document.getElementById("first").value = first;
} </script>
</head>
<body>
<form action="action.php" method="post">
<input type="text" name="usename" value="" id="first" >
<a href="testjavascript.html?auto=1" onclick="updateUsername();" id ="link">Link</a>
<input type="submit" name="submit">
</form>
</body>
【问题讨论】:
-
您的代码等于:
var a= "a"; var b = a; a = b;非常有帮助! -
看起来您正在获取
first的值,然后将其重新分配回同一字段?您试图从哪个字段获取值以及将其放在哪里? -
我希望当我点击 href 链接时 name="username" 和 id="first" 的字段内容保持不变
标签: javascript forms populate