2012-10-04 61 views
0
function getSelectedCopyDates() { 
      var arr = new Array(); 
       //for every row that has a checked checkbox 
       $("tr").has(".noteCheckBox:checked").each(function (i) { 
        if ($(this).id !== "checkAllNotes"){//since this doesn't have a "abbr=..." it breaks the code below "# syntax error" 
         //push the value of column(FName, LName) into the array 
         arr.push($("#" + this.id + "> td[abbr='EventDate'] > div").text()); 
        } 
       }); 
      return arr; 
     } 

回答

3

如果 「單元格值」,你只是希望獲得<td>內的文本,那麼你可以做這樣的事情this

HTML

<table> 
    <tr> 
     <td align="center" abbr="FName, LName">RAWR</td> 
    </tr>   
</table>​ 

jQuery的

$("td[abbr='FName, LName']").text(); 

您可以使用jQuery的.text()方法給定元素中獲得的價值。

編輯

看見你需要得到只有<td> S其中它們含有被選中的複選框,所以這可能爲你工作:

$("td[abbr='FName, LName'] > input:checked").parent().text(); 

找到所有包含該td[abbr='FName, LName'輸入被檢查,然後獲取該元素父文本。

EXAMPLE

//You won't need the on change event for you code. I only added it here to show you what happens when there are values and when there are no values. 

$("input").on("change", function(){ 
    var arr = new Array(); 

    //for every row that has a checked checkbox 
    $("tr").has(".noteCheckBox:checked").each(function(i){ 
     //push the value of column 5 (FName, LName) into the array 
     arr.push($("#"+this.id + "> td > div.c5").text());  
    }); 
    //Print the array to the console. 
    console.log(arr); 
});​ 

UPDATED EXAMPLE

編輯

你的功能應該是:

function getSelectedInvestigatorNames() { 
    var arr = new Array(); 

    //for every row that has a checked checkbox 
    $("tr").has(".noteCheckBox:checked").each(function(i){ 
     //push the value of column 5 (FName, LName) into the array 
     arr.push($("#"+this.id + "> td[abbr='FName, LName'] > div").text());  
    }); 

    return arr; 
} 
+0

雖然OP希望通過屬性而不是所有單元格獲取表格單元格,但[abbr = XXXX]將獲得所需的內容。 –

+1

無論如何,你可以告訴我你正在使用的代碼?更新您的原始文章,我會看看。 – Chase

+1

好的,我已經更新了我的答案。我希望它有幫助 – Chase

3

試試這個

這是進去TD文本

$('td[abbr="FName, LName"]').text(); 

OR

$('td[abbr*="FName"][abbr*="LName"]').text(); 

來獲取值試試這

$('td[abbr*="FName"][abbr*="LName"]').attr('value') 

Check Fiddle

UPDATED FIDDLE

+0

唯一的問題是,我所擁有的是抓取所有的值,因爲我有15行,它抓取了15次。我怎樣才能得到它只抓住行檢查複選框 – user1084319

+0

檢查更新的提琴在我的文章.. –

+0

@ user1084319,我已經添加了更新,以及檢查複選框,檢查是否有幫助。祝你好運! – Chase

相關問題