無論我在複選框列表中選中多少個項目,當我查看錶格添加一行時,只檢查第一個複選框的值是添加到我的表中。我試圖通過每個並獲取每個複選框的值插入,但它似乎並沒有工作。任何線索,我搞砸了?只有第一個複選框值被添加到我的表中
在我的jQuery中,我正在運行一個if語句來防止在未選中框的情況下將未定義添加到我的表中。
這裏是一個展示的jsfiddle我whatI做:http://jsfiddle.net/22L9x006/
$(document).on('click', 'input:checkbox[name=certsToValid]', function() {
$newTableRow = '<tr><td><p>' + $('[name=certsToValid]:checked').val() + '</p></td><td><input type="text" placeholder="Credential #..." class="certInput" /></td><td><p>$5.00</p></td><td><div class="removeRow"></div></td></tr>';
$(this).attr('value');
if($.each($('input:checkbox[name=certsToValid]').is(':checked')) && $(this) != undefined) {
$('.certSelections').append($newTableRow);
}
});
花花公子提供一個名稱的複選框更簡單也創造了一個js小提琴 – 2014-11-02 18:46:53
@ Anonymous.XI已經添加了的jsfiddle,謝謝 – Jhauge 2014-11-02 18:55:37