我有一個簡單的表格來模擬甘特圖。這個想法是,每個TD點擊觸發一個隱藏的輸入文本(值的數組)中存儲的值的總和,在TH(TR標籤的第一個子)中可用。這些值的行總和顯示在最終的TD上。TD上的jQuery求和事件點擊
接下來,代碼表:
<table width="100%" cellspacing="0" class="datagrid_ppal">
<tbody>
<tr class="encabezado">
<th rowspan="2" scope="col" width="15%">Area</th>
<th colspan="7" scope="col">Month</th>
</tr>
<tr class="encabezado">
<th scope="col" width="2%">1</th>
<th scope="col" width="2%">2</th>
<th scope="col" width="2%">3</th>
<th scope="col" width="2%">4</th>
<th scope="col" width="2%">5</th>
<th scope="col" width="2%">...</th>
<th scope="col" width="2%">31</th>
</tr>
<tr>
<th scope="row">Area 1<input name="line_config" type="hidden" value="0,5,50" /></th>
<td class="gantt"> </td>
<td class="gantt"> </td>
<td class="gantt"> </td>
<td class="gantt"> </td>
<td class="gantt"> </td>
<td class="gantt">...</td>
<td class="gantt"> </td>
</tr>
<tr>
<th scope="row">Area 2 <input name="line_config" type="hidden" value="0,0,10" /></th>
<td class="gantt"> </td>
<td class="gantt"> </td>
<td class="gantt"> </td>
<td class="gantt"> </td>
<td class="gantt"> </td>
<td class="gantt">...</td>
<td class="gantt"> </td>
</tr>
<tr class="encabezado">
<th scope="row">Total</th>
<td class="total_dia"> </td>
<td class="total_dia"> </td>
<td class="total_dia"> </td>
<td class="total_dia"> </td>
<td class="total_dia"> </td>
<td class="total_dia">...</td>
<td class="total_dia"> </td>
</tr>
</tbody>
</table>
值的陣列的工作原理如下: 數組[0]:關; array [1]:術前; 數組[2]:操作。
這是我用來區分預操作和可操作單元的jQuery代碼。如果某個單元處於非活動狀態,則該區域關閉:
$(document).ready(function() {
$('td.gantt').click(function() {
$(this).toggleClass('preop');
});
$('td.gantt').dblclick(function() {
$(this).toggleClass('operating');
});
});
非活動TD總是等於總和。我想做的事?簡單: 1.如果TD沒有被點擊(無效),那jQuery總是總結TH輸入值[0]。 2.當我單擊或雙擊時,TD.gantt jQuery獲取TH輸入值[1],並將其添加到總數中。
如果任何人都可以幫助解決整個問題,我會很感激。
謝謝。我已經找到了通過「$(this).parent()。children('input:hidden');」來搜索父級,然後
Answer found:http://stackoverflow.com/questions/2950631/jquery-getting-value-from-input-array/2950663#2950663 =) – betacar 2010-06-01 19:32:42
相關問題