2012-05-02 126 views
0

我有4個COLS一個表:如何從表格單元格的內容中提取值?

<table id="myTable"> 
    <th> 
    <td> A </td> 
    <td> B </td> 
    <td> C </td> 
    <td> D </td> 
    </th> 
    <tr> 
    <td> 
     <span>A-1</span> <span>A-3</span> <span>A-5</span> 
    </td> 
    <td> 
     <span>B-2</span> <span>B-3</span> 
    </td> 
    <td> 
     <span>C-3</span> <span>C-4</span> <span>C-7</span> 
    </td> 
    <td> 
     <span>D-1</span> 
    </td> 
    </tr> 
</table> 

我有A,B,C和d下拉用的更改處理(A = 1,B = 2,等等):

@Html.DropDownListFor(model => model.TypeID, new SelectList(Model.Types, "Key", "Value", Model.TypeID)) 

    $('#myTable').change(function() { 
    var type = $(this).val(); 
    if (type == 1) { 
     var tr = $('#current tr')[0]; 
     var td = tr.cells[0].innerHTML; 
     var last = $(td).find(':last-child'); 
     /// how do I get the contents of the last span??? 
    } else if (type == 2) { 
     ... 
    } 

    }); 

最後一個文本框:

@Html.TextBoxFor(model => model.next) 

當用戶圖片從下拉菜單中進行選擇,我想基於什麼是在appropritate表格單元格中的最後一個跨距把合適的「下一個」值。 我似乎無法弄清楚如何得到最後的,並提取的價值。

+0

除了jQuery,你還在用什麼? – Blazemonger

+0

請給我們完整的呈現HTML輸出 – gdoron

+0

它應該是' ..''不​​'。 –

回答

1
$('#myTable').change(function() { 
    var type = +$(this).val(); 
    if (type === 1) { 
     var tr = $('#current tr'); 
     var td = tr.find('td:eq(0)'); 
     var last = td.find('span:last'); 
     var contents = last.html(); 
    } else if (type == 2) { 
     ... 
    } 

    }); 
相關問題