我有,我要追加到形式的按鈕被點擊權當提交隱藏輸入標籤變量名和值。我如何去編碼它?Javascript:如何在點擊提交按鈕時將隱藏的輸入標籤添加到表單中?
這裏是我的代碼:
<script type="text/javascript">
hname="reference";
hvalue="1";
function insertInput(){
document.write("<input type='hidden' name='" + hname + " ' value=' " + hvalue + " '/><br/>");
}
</script>
<form id="form1">
<p><label>Username:</label> <input type="text" name="username" size="10"/></p>
<p><label>Password:</label> <input type="password" name="password" size="10"/></p>
<p id="hidden"><!-- Insert Hidden input tag here --></p>
<button type="submit' onClick="insertInput();">Log In</button>
</form>
我似乎無法得到它的工作。請幫忙!先謝謝了!
切勿使用'document.write',除非您使用的是時間機器發送該代碼的回到1996年... – 2013-03-07 23:35:10