好的,我正在运行一个测试一堆的javascript来查看它们是否被更改,如果它们被更改,我需要查看是否选中了复选框。但是,出于某些原因,我没有使用表单来执行此操作。以下是表格显示的代码:
<table class="db-view-sku-table">
<thead>
<tr>
<th>Merge <br />Callouts</th>
<th>Current Page</th>
<th>Current Callout</th>
<th>New Page</th>
<th>New Callout</th>
<th>MFG SKU</th>
<th>Client SKU</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr class="odd changed_value">
<td class="hidden db-sku-nid">192297</td>
<td class="hidden db-co-nid">212300</td>
<td class="merge"><input type="checkbox" name = "mergeme" class="checked" /></td>
<td class="db-current-page"><a href="/node/212299" target="_blank">6</a></td>
<td class="db-current-co">A</td>
<td class="db-move-page"><input type="text" class="page-select" size="4" value="" /></td>
<td class="db-move-co"><input type="text" class="co-select" size="4" value="A" /></td>
<td class="db-sku"><a href="/plain/node/192297/edit" class="popup" title="Click to view global SKU details in popup window.">AAG794200</a></td>
<td class="db-client-sku editable-text">AAG-794200</td>
<td class="db-description">AT-A-GLANCE Sorbet Wkl/Mthly Plnr</td>
</tr>
<tr class="even changed_value">
<td class="hidden db-sku-nid">97160</td>
<td class="hidden db-co-nid">212301</td>
<td class="merge"><input type="checkbox" name = "mergeme" class="checked" /></td>
<td class="db-current-page"><a href="/node/212299" target="_blank">6</a></td>
<td class="db-current-co">A</td>
<td class="db-move-page"><input type="text" class="page-select" size="4" value="" /></td>
<td class="db-move-co"><input type="text" class="co-select" size="4" value="A" /></td>
<td class="db-sku"><a href="/plain/node/97160/edit" class="popup" title="Click to view global SKU details in popup window.">AAG76PN0105</a></td>
<td class="db-client-sku editable-text">AAG-76PN0105</td>
<td class="db-description">QUICKNOTES WKLY/MNTH, SPECIAL EDITION</td>
按下保存按钮时的代码:
function setupMassSave() {
$('.save-button').click(function() {
var merge = getMergeList();
var skus = getSkuList();
var pages = getPageList();
var callouts = getCalloutList();
var currco = getCurrCalloutList();
$.ajax({
url: '/skumove/save_all/' + merge + '/' + skus + '/' + pages + '/' + callouts + '/' + currco,
cache: false,
success: refreshView
});
});
}
function getSkuList() {
var slist = [];
$('.changed_value').each(function(index) {
if(!$(this).children('.merge').children('.checked').checked){
slist.push($(this).children('.db-sku-nid').text());
}
});
return slist;
}
function getMergeList() {
var mlist = [];
$('.changed_value').each(function(index) {
if($(this).children('.merge').children('.checked').checked) {
mlist.push($(this).children('.db-sku-nid').text());
}
});
return mlist;
}
我唯一遇到问题的是这两个功能。他们的其他3个功能正常工作并返回我需要的值。我知道问题出在('.merge')的某个地方。点击区域。
感谢您的帮助。
答案 0 :(得分:4)
.checked
是一个(布尔)vanilla JavaScript属性,您尝试将其应用于jQuery对象。这就是它无法正常工作的原因。
替换
$(this).children('.merge').children('.checked').checked
使用
$(this).children('.merge').children('.checked')[0].checked
或
$(this).children('.merge').children('.checked').is(':checked')
或
$(this).children('.merge').children('.checked:checked').length
答案 1 :(得分:1)
使用伪选择器:检查而不是类选择器.checked
if($(this).children('.merge').children(':checked').length) {
mlist.push($(this).children('.db-sku-nid').text());
}