jQuery checkbox事件

来源:互联网 发布:北京algorithm算法 编辑:程序博客网 时间:2024/06/07 02:21
<table id="tableList" class="table table-bordered table-condensed dataTables-example dataTable no-footer"><thead ><tr id="tt"><th align="center">节次</th><th align="center">星期一</th><th align="center">星期二</th><span style="white-space:pre"></span><th align="center">星期三</th></tr></thead>
<span style="white-space:pre"></span><tbody><input class=" form-control input-sm"  name="weekAndlessons" id="weekAndlessons" value=""/><!-- 获取周节 --><span style="white-space:pre"></span><c:forEach items="${sectionList}" var="sectionList" varStatus="status"><tr align="center" id="tr2"> <td>${sectionList}</td><!-- 循环节次 --> <td class="td" id="${sectionList}-1"><!-- 获取的是1-1  代表节次1和星期一  将星期固定 --> <c:set var="havevalue" scope="page" value="false" /> <c:forEach items="${scd }" var="scd"><c:if test="${scd.weekday=='1'&&scd.lessons==sectionList}"><c:set var="havevalue" scope="page" value="true" /><span><i class="glyphicon glyphicon-ok" style="color: rgb(212, 106, 64);font-size:20px;" ></i></span></c:if> </c:forEach><c:if test="${havevalue=='false' }"><input type="checkbox" name="zj" ></c:if> </td><td class="td" id="${sectionList}-2"><c:set var="havevalue" scope="page" value="false" /> <c:forEach items="${scd }" var="scd"><span style="white-space:pre"></span><c:if test="${scd.weekday=='2'&&scd.lessons==sectionList}"><c:set var="havevalue" scope="page" value="true" /><span><i class="glyphicon glyphicon-ok" style="color: rgb(212, 106, 64);font-size:20px;" ></i></span></c:if> </c:forEach><c:if test="${havevalue=='false' }"><input type="checkbox" name="zj" ></c:if></td><td class="td" id="${sectionList}-3"><c:set var="havevalue" scope="page" value="false" /> <c:forEach items="${scd }" var="scd"><span style="white-space:pre"></span><c:if test="${scd.weekday=='3'&&scd.lessons==sectionList}"><span style="white-space:pre"></span><c:set var="havevalue" scope="page" value="true" /><span style="white-space:pre"></span><span><i class="glyphicon glyphicon-ok" style="font-size: 20px;color: rgb(212, 106, 64);"></i></span></c:if> </c:forEach><c:if test="${havevalue=='false' }"><input type="checkbox" name="zj" ></c:if></td></tr></c:forEach> </tbody>
</table><


表格中复选框,点击checkbox分别获取checkbox里的值,选中将值赋值到隐藏到表单域里,取消选中删除

$(function(){$("input[name='zj']").click(function(){var tdParent =  $(this).parent(".td").attr("id");var wal =  $("#weekAndlessons").val();//隐藏域表单if($(this).prop("checked")){//选中状态 wal+=tdParent+",";//拼接$("#weekAndlessons").val(wal); //赋值$(this).attr("checked",true);}else{$("#weekAndlessons").val($("#weekAndlessons").val().replace((tdParent+","),''));//取消选择,删除表单域增加的值$(this).attr("checked",false);} });})



0 0
原创粉丝点击