2012-09-13 220 views
1

好吧,我正在運行一個測試一堆以查看它們是否已更改的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')。點擊區域內。

感謝您的幫助。

回答

4

.checked是(布爾)香草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 
+0

我用下面的:01 ($:this).children('。merge')。children('。checked')。is(':checked')){\t if – webdevsoup

1

使用僞選擇:而不是檢查得到的類別選擇的.checked

if($(this).children('.merge').children(':checked').length) { 
    mlist.push($(this).children('.db-sku-nid').text()); 
}