我找到了 this几乎正是我想要做的。我正在使用 Jeditable我可以使用默认设置。我还能够使上面论坛中的代码正常工作。我相信我的问题是,因为我使用的是表格,所以我需要做其他事情来选择前一个元素。
这是我的 HTML
<table>
<tr>
<td width="5%"><input class="cat_checkbox" type="checkbox" name='delete_cat[]' value='<?php echo("$cat_data[cat_id]");?>' /></td>
<td width="90%" class="edit_cat_title" id='unique_id'>Category</td>
<td width="5%"><a href="#" class="edit_cat_title_trigger"><img src="images/edit.gif" border="0"></a></td>
</tr>
</table>
这是我的 JQuery:
//modify title content on the fly
$('.edit_cat_title').editable('action.php', {
name : 'cat_title',
indicator : 'Saving...',
submit : 'OK',
cancel : 'Cancel',
tooltip:'click to edit',
event : 'edit'
});
//trigger with the click of the edit image
$(".edit_cat_title_trigger").bind("click", function() {
$(this).prev().trigger("edit_cat_title");
});
我知道我可能应该能够弄清楚,我知道我所要做的就是将 $(this).prev().trigger("edit_cat_title");
更改到右边事情,但我对 Jquery 还是很陌生。
最佳答案
与其依赖 dom 结构来触发编辑事件,不如考虑在两者上设置一个 rel 标签,以便对它们进行更有限的分组。这将使您的代码与标记更加分离。那么选择器就是 $('.edit_cat_title').filter('[rel='+$(this).attr('rel')+']')
关于javascript - 使用 Jeditable 并在点击时激活,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1586825/