如何使用文本表单的id更改隐藏表单的值?我有一些类似以下的东西:
<form name="form" action="file.php" method="post">
<input type="hidden" name="dessert" id="dessert" value="">
Favorite cake: <input type="text" name="cake" id="cake" onfocus="dessert.value=this.id"><br>
Favorite pie: <input type="text" name="pie" id="pie" onfocus="dessert.value=this.id"><br>
Favorite taffy: <input type="text" name="taffy" id="taffy" onfocus="dessert.value=this.id"><br>
<input type="submit value="Go."><br>我对html非常不熟悉,所以在使用文本输入的id来更改隐藏表单的值时遇到了麻烦。
发布于 2012-07-12 03:08:10
尝试:
<form name="form" action="file.php" method="post">
<input type="hidden" name="dessert" id="dessert" value="">
Favorite cake: <input type="text" name="cake" id="cake" onfocus="document.getElementById('dessert').value=this.id"><br>
Favorite pie: <input type="text" name="pie" id="pie" onfocus="document.getElementById('dessert').value=this.id"><br>
Favorite taffy: <input type="text" name="taffy" id="taffy" onfocus="document.getElementById('dessert').value=this.id"><br>
<input type="submit value="Go."><br>使用以下格式:
onfocus="document.getElementById('dessert').value=this.id"发布于 2012-07-12 03:01:34
你的代码可以工作,你只是有一个语法错误。
<input="hidden" name="dessert" id="dessert" value="">应该是:
<input type="hidden" name="dessert" id="dessert" value=""> 注意"type=“
适用于Chrome:fiddle
https://stackoverflow.com/questions/11439491
复制相似问题