1
當用戶單擊表格行尾部的按鈕時,我需要一些幫助從表格中拉取單元格數據。該表是通過Ajax技術生成的。我不確定訪問表格中的元素是否有所幫助。jQuery - 從表中提取單元格數據
<script type='text/javascript' src='jquery.js'></script>
<p>** click me **</p>
<br/>
<div id="placeHolder">some text goes here!</p>
<script>
$("p").click(function() {
$.ajax({
url: "status_2.html",
cache: false,
success: fnSuccess
}
);
});
function fnSuccess(msg)
{
$('div#placeHolder').html(msg);
}
function selectEditActivity(pass_id){
var row = $('#'+pass_id);
var seq = row.attr('seq');
// here I would like to pull the value of the date from the selected row
// but I just can't get syntax right. I get a null value on alert
var from_date = $('td', row).eq(0).html();
alert(from_date);
}
</script>
這是獲取閱讀HTML代碼(文件:status_2.html)
<span id="status2">
<span id="response" class="response"></span>
<table class="tableBorder">
<tr >
<th class="align_left">Date</th>
</tr><tr>
<tr seq="1" class="row_theme2" id="id3014201105191"></tr>
<tr><td>20090519</td>
<td>1330</td>
<td>1430</td>
<td>LUNCH</td>
<td></td>
<td><a onclick="selectEditActivity('id3014201105191');" href="#">EDIT</a></td>
</tr>
<tr seq="2" class="row_theme2" id="id3014201105192"></tr>
<tr><td>20100519</td>
<td>1330</td>
<td>1430</td>
<td>LUNCH</td>
<td></td>
<td><a onclick="selectEditActivity('id3014201105192');" href="#">EDIT</a></td>
</tr>
<tr seq="3" class="row_theme2" id="id3014201105193"></tr>
<tr><td>20110519</td>
<td>1330</td>
<td>1430</td>
<td>LUNCH</td>
<td></td>
<td><a onclick="selectEditActivity('id3014201105193');" href="#">EDIT</a></td>
</tr>
</tbody></table>
brillant!我總是有這種類型的例子的問題。有沒有更好的方式來表達這種解決方案? – 2011-05-19 04:16:23
@ bob的你的兄弟:你問是否有更好的方法來實現這個目標?如果是這樣,你可能想考慮讓jQuery處理你的事件處理程序。你可以去掉內聯的onclick處理程序,只需從被點擊的DOM中遍歷DOM。我會給一個更新, – user113716 2011-05-19 04:19:27