两种实现方法一个是把值送过去,一个是自己来取值。
第一种方法:
A页面:
<form id="t6" name="t6" method="post" action="">
<input type="checkbox" name="aa" value="1">1
<input type="checkbox" name="aa" value="2">2
<input type="checkbox" name="aa" value="3">3
<input type="checkbox" name="aa" value="4">4<br>
<input type="button" value="提交" onClick="fun3()">
</form>
js:
function fun3(){
var checkBox = documentt6aa;
var msg = "";
for(var i=0;i<checkBoxlength;i++){
if(checkBox[i]checked){
msg += checkBox[i]value + "|";
}
}
if(msg != ""){
msg = msgsubstring(0,msglength-1);
}
documentt6action = "Untitled-4htmlmsg="+msg;
documentt6submit();
}
B页面:
<body>
<button onClick="show_popup()">查看</button>
</body>
js:
function show_popup(){
var str = documentlocationsearchsubstring(1);
var params = strsplit("|");
alert(params);
}
第二种方法:
在你提交的form里用target="_blank"将B页面在一个新窗口中打开
然后b页面可以通过openerdocumentt6aa回到他的父页面来取值,具体代码不写了,思路就是这样的。
这个简单,假如你的表格id为table,表格第一列为checkbox,然后在checkbox选中的情况下将表格所有第二列中的数据放到一个数组中 var data = [];$(function(){ $("#table")find(":checkbox:checked")each(function(){ var val = $(this)parent
(1)input的checked是一个html属性,checked的值没有意义,只不过各个版本对HTML的属性值写法规定不同才有了checked="value"这种写法,只要有checked就表示页面在加载的时候checkbox被选中,没有写就页面加载的时候checkbox就不被选中。
(2)同一个页面中用js获取checkbox是否选中:documentgetElementById("checkboxId")checked
(3)jsp中在提交时,浏览器会把选中的CheckBox的Value值,添加到一个String数组当中。在Servlet(jsp)中用
String[]
chk
=
requestgetParameterValues("CheckBox的名字");就能可到所有被选择的CheckBox值,如果没有选择则数组:chk
为null。
自己测试下就知道了
Action里面:
private PromotionManageTo promotionManageTo;
private List<PromotionManageTo> productClass;
get…
set…
SqlMaps里面:
<select resultClass="promotionManagePromotionManageTo">
……
</select>
JSP里面:
<s:iterator value="productClass" status="productClassLength">
<td>
<input type="checkbox" name="promotionManageToproductId" value="<fs:property value="productId"/>" <c:if test="${fn:containsIgnoreCase(promotionManageToproductId, productId)}">checked="checked"</c:if> />
</td>
</s:iterator>
后台取值,bool isCheck = thischeckBox1Checked;
前台js取值则用 documentgetElementById("checkBox1")checked;
1:使用requestgetParameterValues(keyName)获取checkbox、select值;
在使用过程,如果select使用id标识,而不是name,则getParameterValues返回“”。
2:客户端控件在服务器端不能获取。必须加上runat="server"。
if(Checkboxchecked==true)
{
//选中状态
}
else
{
//未选中状态
}
只有这种方式,不加runat="server",后台无法获取。
在服务器中获取客户端的值必须让其变成服务器端控件。
在客户端即可获取客户端控件的值,也可获取服务器端控件的值,说白了说是脚本。
3:if (ckSysChecked == true)
{
userLimitLevel = thisckSysText;
}
if (ckBasicChecked == true)
{
userLimitLevel = thisckBasicText;
}
if (ckInforChecked == true)
{
userLimitLevel = thisckInforText;
}
if (ckTableChecked == true)
{
userLimitLevel = thisckTableText;
}
自己试试吧
1、首先创建一个名称为 checkbox_form_id的html文件 。
2、添加2个input元素 设置input类型为checkbox设置并分别设置id,添加一个form设置id为“thisisformid”。
3、添加一个button按钮,在点击事件中加入自定义函数my_checkbox_form_id,添加一p标签,设置id 为 show_checkbox_form_id。
4、在javascript中创建一个自定义函数 my_checkbox_form_id。
5、在自定义函数中获取input对象。用form属性获取表单对象,用表单的id属性获取表单的id值,并将结果显示到p标签中。
6、最后在浏览器中打开文件,点击button查看获取到的表单id效果。
楼主你为什么不用VS自带的控件呢 非要用HTML
而且你那个是<input type="checkbox" >
如果非要用HTML 控件要让后台访问到必须加入runat="server" 也就是
<input type="checkbox" runat="server" >
还是不明白的话整段代码给你吧
前台代码
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default5aspxcs" Inherits="Default5" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 10 Transitional//EN" ">
以上就是关于怎么获取checkbox的状态全部的内容,包括:怎么获取checkbox的状态、如何获取table中checkbox 选中行中列的数据、JSP中如何获取checkbox的状态(选中或非选中)等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)