1

我发现几乎正是我想要做的。我正在使用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 仍然很陌生。

4

2 回答 2

2

与其依赖 dom 结构来触发编辑事件,不如考虑在两者上设置一个 rel 标记,以便更有限地对它们进行分组。这将使您的代码与您的标记更加分离。那么选择器就是$('.edit_cat_title').filter('[rel='+$(this).attr('rel')+']')

于 2009-10-19T08:59:10.933 回答
1

我想通了,我只需要.edit_cat_title为任何想知道的人获取我使用这个 jquery 的前一个实例。

    $(".edit_cat_title_trigger").bind("click", function() {
    $(this).parent().prev('.edit_cat_title').trigger("edit");
});

谢谢

于 2009-10-19T03:50:33.587 回答