我这里有这个简单的Html代码。
<form action="" method="post">
Text Box:<input type="text" name="host" value="default value" size=30 onchange="updateTextBox()" />
<input type="submit" name="submit" value="update value in text box to current value"/>
</form>
每次单击按钮,我都希望文本框的默认值更新为我最近输入的值。
答案 0 :(得分:1)
<script>
/* give a name to the form and write it where "form_name" is */
var newText = document.forms["form_name"]["host"].value;
/* add this chunk in the submit button (onclick = "changeText()") */
function changeText()
{
/* give an id to the text box input tag and replace "input_id" with that */
document.getElementById("input_id").value = newText;
}
</script>