jquery获取选中的checkbox并提交form表单

/HTML

<form method="POST" name="subForm" id="subForm" action="/report/mail/redirectEmail/" enctype="multipart/form-data">

<input type="checkbox" name="memberContactIds" value="${memberContacts.id}" style="width:15px;" checked="checked">

<input type="button" οnclick="send_emails()" value="点击">

</form>



//JS

function send_emails(){
var sel = $("input:checkbox[checked=true]");
if(sel.length == 0){
alert("请选择收件人!");
return false;
}else{
$("#subForm").submit();
loading();
}
}

//Action

public String redirectEmail(Long memberId, Long[] memberContactIds, @RequestParam(value = "fileString", required = false) MultipartFile[] fileString, @ModelAttribute Report report, BindingResult result, SessionStatus status, Model model, HttpServletRequest request, HttpServletResponse response)
{
StringBuffer sb = new StringBuffer();
if (null != memberContactIds && memberContactIds.length > 0)
{
for (Long l : memberContactIds)
{
System.out.println(l);
sb.append(l+","); //用逗号拼成这样的形式: 111,222,333,
}
}
List<String> fileStrings = new ArrayList<String>();
report.setType(0);
report.setSendType(4);// 给一个公司下面的多个用户发送
report.setMemberContactIds(sb.toString());

String[] ids = report.getMemberContactIds().split(",");

if (null != ids && ids.length > 0)
{
for (String id : ids)
{
MemberContact memberContact = memberContactService.findById(Long.valueOf(id));
}
}
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
在 HTML 中,checkbox 是一种 input 类型,用于让用户选择一项或多项选项。当用户提交包含 checkbox时,需要获取用户所选的值。 可以通过以下方式来获取 checkbox 的值: 1. 使用 JavaScript: ```html <form> <input type="checkbox" name="fruit" value="apple"> Apple<br> <input type="checkbox" name="fruit" value="banana"> Banana<br> <input type="checkbox" name="fruit" value="orange"> Orange<br> <button onclick="getCheckboxValue()">Submit</button> </form> <script> function getCheckboxValue() { var checkboxes = document.getElementsByName("fruit"); var values = []; for (var i=0; i<checkboxes.length; i++) { if (checkboxes[i].checked) { values.push(checkboxes[i].value); } } console.log(values); } </script> ``` 在此示例中,我们使用了 `document.getElementsByName()` 方法来获取所有名称为 "fruit" 的 checkbox 元素,然后使用 `for` 循环遍历所有 checkbox,如果 checkbox选中,则将它的值添加到数组中。最后,我们将数组打印到控制台。 2. 使用 jQuery: ```html <form> <input type="checkbox" name="fruit" value="apple"> Apple<br> <input type="checkbox" name="fruit" value="banana"> Banana<br> <input type="checkbox" name="fruit" value="orange"> Orange<br> <button id="submit-btn">Submit</button> </form> <script src="https://code.jquery.com/jquery-3.6.0.min.js"></script> <script> $("#submit-btn").click(function() { var values = []; $("input[name='fruit']:checked").each(function() { values.push($(this).val()); }); console.log(values); }); </script> ``` 在此示例中,我们使用 jQuery 的选择器来获取所有名称为 "fruit" 的 checkbox 元素,并使用 `each()` 方法遍历所有选中checkbox。然后,我们将它们的值添加到数组中,并将数组打印到控制台。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值