有关input按钮中checkbox的复选提交前端处理学习总结

jsp前端文件中:
			<tr>
		        <td align="right" width="50%">其他账户:</td>
		        <td align="left"><p id="userName">${userName}</p></td>
		      </tr>
             <tr>
		        <td align="right" valign="top" width="50%" style="padding-top:20px;">账户列表:</td>
		        <td align="left" valign="top">
		        	<c:forEach  items="${accounts}" var="account">	        		
		        		<p><input type="checkbox" name="businessId" value="${account.id}" data="${account.name }" <c:if test="${account.state=='0'}">checked="checked" disabled="disabled"</c:if>/>${account.name }</p>
		        	</c:forEach >
		        </td>
		     </tr>	
		input中每个属性:type="checkbox" 表示input类型为复选框 即可选择,可取消选择;
						name="businessId" form表单提交时根据这个属性	
						data="${account.name }表示该复选框的值;
						checked="checked"表示对这个选择框进行了选择;
						disabled="disabled"表示不可进行选择和取消选择操作

js中处理:		
		$('#confirm').click(function(){
		//选中的账户id集合,用逗号分隔
		var businessIds="";
		//选中的账户名集合,用顿号分隔
		var businessNames="";	
		var userName=$('#userName').html();
		
		$("input[name='businessId']:checkbox").each(function(){
			if ($(this).get(0).checked && $(this).attr("disabled")!="disabled") {
				alert(this)
				businessIds += $(this).attr('value')+','; 
				alert(businessIds);
				businessNames+=$(this).attr("data")+"、";
				alert(businessNames);
			  } 
			}); 
		
		businessIds=businessIds==""?businessIds:businessIds.substr(0,businessIds.length-1);
		businessNames=businessNames==""?businessNames:businessNames.substr(0,businessNames.length-1);
		$('#businessIds').val(businessIds);
		
		if(businessIds==""){
			$.messager.alert("提示","请选择需要添加的账户");
			return;
		}




  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值