使用 jQuery 编辑添加到表中的行
我找到了这篇文章: 编辑和删除新添加的表row 使用 Jquery ,这似乎正是我正在寻找的,但我无法让他们建议的解决方案发挥作用。
进行 ajax 调用后,我向表中添加一个新行。该行看起来与此类似:
<tr class="classRow" bgcolor="#EFE5D3" style="font-weight: bold; font-size: 1.1em;">
<td width="35px"><a class="classEditLink classAdminFormSubmit" name="33" href="#">Edit</a></td>
<td width="20px"><input type="checkbox" class="chkDeleteClass" name="deleteClasses[]" value="33" /></td>
<td>CLASS101</td>
<td>Class Description</td>
</tr>
“编辑”链接只有在页面刷新后才起作用(我假设这与它在添加到表后并未立即出现在 DOM 中有关)。因此,我需要找到一种解决方法,这使我看到了上述帖子。
我从那里修改了代码,如下所示:
$('a').live('click', function(e){
if ($(e.target).attr('class') == 'classAdminFormSubmit') {
alert($(e.target).name());
OpenEditDialog($(this));
return false;
}
});
警报永远不会触发,所以我希望这只是我的选择器需要调整。我需要将选定的锚标记传递给 OpenEditDialog 函数。
I found this post: Editing and deleting a newly added table row using Jquery and that seemed like it was exactly what I was looking for, but I couldn't get their suggested solution to work.
After making an ajax call, I add a new row to a table. The row looks similar to this:
<tr class="classRow" bgcolor="#EFE5D3" style="font-weight: bold; font-size: 1.1em;">
<td width="35px"><a class="classEditLink classAdminFormSubmit" name="33" href="#">Edit</a></td>
<td width="20px"><input type="checkbox" class="chkDeleteClass" name="deleteClasses[]" value="33" /></td>
<td>CLASS101</td>
<td>Class Description</td>
</tr>
The Edit link doesn't work until after a page refresh (I'm assuming that has something to due with the fact that it's not in the DOM immediately after it's added to the table). So, I needed to find a workaround, which lead me to the above-mentioned post.
I modified the code from there to look like this:
$('a').live('click', function(e){
if ($(e.target).attr('class') == 'classAdminFormSubmit') {
alert($(e.target).name());
OpenEditDialog($(this));
return false;
}
});
The alert never fires, so I'm hoping it's just that my selector needs adjusting. I need to pass the selected anchor tag to the OpenEditDialog function.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
首先,在刚刚添加的行中放置一个链接,并为其指定一个类,假设它是
editRow
。其次,使用此代码:
First, put a link in the row you just added, and give it a class, let's say it's
editRow
.Second, use this code: