我将一些旧代码从另一个库移动到jQuery,并在此过程中破坏了其他一些代码。我认为jQuery实现其.html
函数的方式让我感到悲伤。
以下部分是使用以下语法通过AJAX调用生成函数生成的:$('#status2').html(response);
<!-- Section DivPlaceholders - this is required for ajax call -->
<span id="status"></span>
<span id="status2">
<span id="response" class="response"></span>
<table class="tableBorder">
<tbody><tr class="row_header thin_border">
<th class="align_left">Date</th>
<th class="align_left">From</th>
<th class="align_left">To</th>
<th class="align_left">Activity</th>
<th class="align_left">P.Code</th>
<th class="align_left">Del</th>
<th class="align_left">Edit</th>
</tr><tr>
<!-- section: SchedResponse -->
<tr seq="1" class="row_theme2" id="id3014201105191"></tr>
<tr><td>20110519</td>
<td>1330</td>
<td>1430</td>
<td>LUNCH</td>
<td></td>
<td><a onclick="deleteActivity(3014,20110519,1);" href="#"> <img src="img/deleteAction.png"></a></td>
<td><a onclick="selectEditActivity("id3014201105191");" href="#"><img src="img/editAction.png"></a></td>
</tr>
</tbody></table>
现在我在var from_date = cells[0].innerHTML;
function selectEditActivity(pass_id){
var row = document.getElementById(pass_id),
seq = row.getAttribute("seq"),
cells = row.getElementsByTagName("td");
var from_date = cells[0].innerHTML;
var from_time = cells[1].innerHTML;
}
(谢谢保罗)
答案 0 :(得分:0)
为什么你也不使用jQuery?试试吧:
function selectEditActivity(pass_id){
var row = jQuery('#' + pass_id); // Workaround
seq = row.attr('seq');
cells = row.find('td');
var from_date = cells.eq(0).html(); // better .text() I guess
var from_time = cells.eq(1).html(); // here too
}
修改:代码已修复。感谢@Domenic。
答案 1 :(得分:0)
function selectEditActivity(pass_id){
var row = $('#'+pass_id);
var seq = row.attr('seq');
var from_date = $('td', row).eq(0).html();
var from_date = $('td', row).eq(1).html();
}