Javascript 从复选框表中获取值
我有一个复选框表:Javascript 从复选框表中获取值,javascript,jquery,twitter-bootstrap,checkbox,Javascript,Jquery,Twitter Bootstrap,Checkbox,我有一个复选框表: <div> <h1 class="text-center">Link activities</h1> <div class="row"> <div class="col"></div> <div class="col-md-8 col-lg-8"> <h3>Link activities to txn/even
<div>
<h1 class="text-center">Link activities</h1>
<div class="row">
<div class="col"></div>
<div class="col-md-8 col-lg-8">
<h3>Link activities to txn/events</h3>
<div class="table-responsive">
<table class="table table-bordered">
<thead>
<tr>
<th></th>
<th colspan="3">Txn/event</th>
</tr>
<tr>
<th>Activity</th>
<th class="text-center" style="background-color: khaki">Click & Collect</th>
<th class="text-center" style="background-color: khaki">Delivery</th>
<th class="text-center" style="background-color: khaki">Walk-in</th>
</tr>
</thead>
<tbody>
<tr>
<th scope="row" style="background-color: #eed3d7">Till</th>
<td class="text-center"><input type="checkbox" aria-label="Till/C&C" value="Till/C&C" /></td>
<td class="text-center"><input type="checkbox" aria-label="Till/Del" value="Till/Del" /></td>
<td class="text-center"><input type="checkbox" aria-label="Till/Walk" value="Till/Walk" /></td>
</tr>
<tr>
<th scope="row" style="background-color: #eed3d7">Delivery</th>
<td class="text-center"><input type="checkbox" aria-label="Del/C&C" value="Del/C&C" /></td>
<td class="text-center"><input type="checkbox" aria-label="Del/Del" value="Del/Del" /></td>
<td class="text-center"><input type="checkbox" aria-label="Del/Walk" value="Del/Walk" /></td>
</tr>
<tr>
<th scope="row" style="background-color: #eed3d7">Pick</th>
<td class="text-center"><input type="checkbox" aria-label="Pick/C&C" value="Pick/C&C" /></td>
<td class="text-center"><input type="checkbox" aria-label="Pick/Del" value="Pick/Del" /></td>
<td class="text-center"><input type="checkbox" aria-label="Pick/Walk" value="Pick/Walk" /></td>
</tr>
</tbody>
</table>
</div>
</div>
<div class="col"></div>
</div>
<div class="row">
<div class="col"></div>
<div class="col-md-8 col-lg-8 align-self-center text-right">
<button type="button" class="btn btn-secondary">Cancel</button>
<button type="button" class="btn btn-primary" id="linkUpdate">Update</button>
</div>
<div class="col"></div>
</div>
</div>
但是,这目前给了我一个错误:
Uncaught TypeError: Cannot read property 'toLowerCase' of undefined
at jQuery.fn.init.val (jquery.js?ae28:7935)
at HTMLInputElement.eval (project.js?9e26:21)
at Function.each (jquery.js?ae28:362)
at jQuery.fn.init.each (jquery.js?ae28:157)
at HTMLButtonElement.eval (project.js?9e26:20)
at HTMLButtonElement.dispatch (jquery.js?ae28:5206)
at HTMLButtonElement.elemData.handle (jquery.js?ae28:5014)
所以。我的问题分为两部分:
1) 在按下更新按钮之前,是否需要将复选框的状态设置为选中
2) 当我按下更新按钮时,如何获取选中复选框的值
我使用的是bootstrapversion4.0.0-alpha.6
和jqueryversion3.2.1
在此方面的任何帮助都将不胜感激
谢谢您的时间。用函数()替换()=>
,演示:
$(“#链接更新”)。在('click',function()上{
让selectedLinks=[];
$(“输入:复选框:选中”)。每个(函数(){
selectedLinks.push($(this.val());
});
console.log(selectedLinks);
});代码>
链接活动
将活动链接到txn/事件
Txn/事件
活动
单击并收集
传送
走进
直到
传送
挑
取消
更新
用函数()替换()=>
,演示:
$(“#链接更新”)。在('click',function()上{
让selectedLinks=[];
$(“输入:复选框:选中”)。每个(函数(){
selectedLinks.push($(this.val());
});
console.log(selectedLinks);
});代码>
链接活动
将活动链接到txn/事件
Txn/事件
活动
单击并收集
传送
走进
直到
传送
挑
取消
更新
我想你需要$(':input:checked')
我想你需要$(':input:checked'))
是的,修复了它,尽管我不明白为什么在我使用babel编译所有javascript代码时arrow函数会破坏它?是的,修复了它,尽管我不明白为什么在我使用babel编译所有javascript代码时arrow函数会破坏它?
Uncaught TypeError: Cannot read property 'toLowerCase' of undefined
at jQuery.fn.init.val (jquery.js?ae28:7935)
at HTMLInputElement.eval (project.js?9e26:21)
at Function.each (jquery.js?ae28:362)
at jQuery.fn.init.each (jquery.js?ae28:157)
at HTMLButtonElement.eval (project.js?9e26:20)
at HTMLButtonElement.dispatch (jquery.js?ae28:5206)
at HTMLButtonElement.elemData.handle (jquery.js?ae28:5014)