我已经在stackoverflow中的某处读过,我们不会得到复选框的值,显示:none使用javascript,但我得到了servlet中checkbox的值。
以下是我的JSP代码
<script type="text/javascript">
function hideData(){
document.getElementById("checkBoxTest").style.display="none";
}
</script>
<form action="DisplayServlet" method="get" >
<input type="checkbox" value="CheckboxTest" id ="checkBoxTest" name = "checkBoxTest" checked/>Test <br/>
<a href="#" onclick = "return hideData();">Click to hide check box </a> <br/>
<input type="submit" value="Submit" />
</form>
但即使我隐藏它,我也会得到复选框的值。但是在stackoverflow中的某处我读到了visibility:hidden会给出值而display:none将为null值。
我正在获取值的servlet代码。
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
String checkBoxValue = request.getParameter("checkBoxTest");
System.out.println("checkBoxValue ====== "+checkBoxValue);
}
答案 0 :(得分:0)
我猜你误解了display:none
display:none means that the the tag in question will not appear
on the page at all (although you can still interact with it through the dom).
There will be no space allocated for it between the other tags.
还有你的问题,
Will I get the display: none input value in servlet?
不,你不会。
尝试此操作,因为您可能会错过点击href按钮,将javascript函数添加到表单
<form action="DisplayServlet" method="get" onsubmit="return hideData();">
否则将input
标记设为
<input type="checkbox" value="CheckboxTest" id ="checkBoxTest" name = "checkBoxTest" style="display: none"/>
希望这会有所帮助!!