正常情況下form表單提交會把表單內的內容提交到后台,但是如果有些內容只是作為展示或者是標記而不想傳到后台,我們采用如下方法:
jsp頁面如下,我們不想提交id為userIdMark和pwdMark的input框的值到后台,所以我們需要在提交時設置input框的屬性為disabled,
這樣當表單提交時,他們的值就無法提交到后台,從而達到目的
<form action="${path }/manage/logon.do" method="post" id="logonForm"> <table cellpadding="0" cellspacing="0" border="0"> <tr height="50"> <td> <input type="text" id="userIdMark" name="userIdMark" style="line-height:20px; height:20px;width: 150px;"/> <input type="hidden" id="userId" name="userId" style="line-height:20px; height:20px;width: 150px;"/> </td> </tr> <tr height="50"> <td> <input type="password" id="pwdMark" name="pwdMark" style="line-height:20px; height:20px;width: 150px;"/> <input type="hidden" id="pwd" name="pwd" style="line-height:20px; height:20px;width: 150px;"/> </td> </tr> <tr height="60"> <td> <a href="#" id="logon" name="submit" class="login_btn"></a> </td> </tr> </table> </form>
js代碼:
$("#logon").click(function(){
document.getElementById("userId").value = "admin";
document.getElementById("pwd").value = "1";
$("#userIdMark").attr("disabled","disabled");
$("#pwdMark").attr("disabled","disabled");
$("#logonForm").submit();
});
這樣后台就只能接收id為userId和pwd的的值,無法接收id為userIdMark和pwdMark的值了
