【发布时间】:2017-03-07 21:31:09
【问题描述】:
如果复选框被选中,返回值为:
/doCheckBox.asp?checkbox-1=true
如果未选中该复选框,我将不会收到任何响应:
/doCheckBox.asp?
有没有办法使用隐藏属性返回未经检查的复选框值?
doCheckBox.asp
<%
Option Explicit
Response.Expires = 0
Dim cb1
cb1 = Request("checkbox-1")
Response.Write(cb1)
%>
checkBox.html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title></title>
<link rel="stylesheet" href="//code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">
<script src="https://code.jquery.com/jquery-1.12.4.js"></script>
<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
<script>
$(document).on("ready", function() {
$('input').checkboxradio();
$('button').button();
$('#button').on('click', function(){
var cb2 = $('#checkbox-2').prop('checked') ? true : false;
var cb1 = $('#checkbox-1').prop('checked') ? true : false;
var cb3 = $('#checkbox-3').prop('checked') ? true : false;
var cb4 = $('#checkbox-4').prop('checked') ? true : false;
var cb5 = $('#checkbox-5').prop('checked') ? true : false;
alert(" " + cb1 + " " + cb2 + " " + cb3 + " " + cb4 + " " + cb5)
submitForm();
});
});
function submitForm() {
$('#form1').attr('action', "doCheckBox.asp").submit( function(){
var cb1 = $('#checkbox-1').prop('checked') ? true : false;
$('#checkbox-1').val(cb1);
});
}
</script>
</head>
<body>
<div class="widget">
<h2>Checkbox</h2>
<form id="form1" method="get">
<fieldset>
<legend>Hotel Ratings: </legend>
<label for="checkbox-1">1 Star</label>
<input type="checkbox" name="checkbox-1" id="checkbox-1">
<label for="checkbox-2">2 Star</label>
<input type="checkbox" name="checkbox-2" id="checkbox-2">
<label for="checkbox-3">3 Star</label>
<input type="checkbox" name="checkbox-3" id="checkbox-3">
<label for="checkbox-4">4 Star</label>
<input type="checkbox" name="checkbox-4" id="checkbox-4">
<label for="checkbox-5">5 Star</label>
<input type="checkbox" name="checkbox-5" id="checkbox-5">
<button id="button" type="submit" onClick="submitForm()">Open Dialog</button>
</fieldset>
</form>
</div>
</body>
</html>
【问题讨论】:
-
通常你不需要那个,因为未选中的复选框不会被发送到后端,它应该映射到默认的
false布尔值。 -
我正在尝试将该错误值返回到 .asp 文件,以便将其填充到数据库中。
-
这就是我要说的。如果您不将值从 UI 传递到后端,则后端中的布尔值将保持其默认值,即
false。 -
我现在明白了,谢谢。
-
如果您明确需要该值,那么将其默认设置在后端是没有用的。这取决于您的要求。
标签: javascript jquery html vb.net checkbox