可编辑-通过单击Y激活X的编辑 [英] Jeditable - Activate edit of X by clicking on Y

查看:78
本文介绍了可编辑-通过单击Y激活X的编辑的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 Jeditable 作为内联编辑解决方案.

I'm trying to use Jeditable as an inline editing solution.

默认行为(单击该元素进行编辑)效果很好,但是我想通过单击另一个元素来激活一个元素.

The default behavior (click on the element to edit it) works quite well, but I would like to activate an element by clicking on another element.

例如,单击a.activateEdit将激活下一个div.edit(显然应使用jQuery选择器完成).

For example clicking on a.activateEdit will activate the next div.edit (obviously should be done using jQuery selectors).

为此,我研究了Jeditable文档,但找不到正确的语法

I've looked into Jeditable docs for this, but couldn't find the right syntax

仅供参考,默认的Jeditable语法类似于以下内容:

FYI, the default Jeditable syntax is something along the lines of:

 $(document).ready(function() {
     $('.edit').editable('http://www.example.com/save.php');
 });

*找到更好的解决方案 *

* found a better solution *

推荐答案

以上代码也不完全正确.它会在所有可编辑实例上触发click事件.

Above code is not quite correct either. It triggers click event on ALL Jeditable instances.

执行此操作的方法有很多,并且都取决于您的HTML,但是例如,如果您具有以下HTML:

There are many ways to do it and it all depends on your HTML, but for example if you have following HTML:

<div class="edit" id="unique_id">Editable text</div> 
<a href="#" class="edit_trigger">Edit me!!</a>

然后您可以使用以下JavaScript:

Then you can use following JavaScript:

/* Bind Jeditable instances to "edit" event. */
$(".edit").editable("http://www.example.com/save.php", {
    event     : "edit"
});
/* Find and trigger "edit" event on correct Jeditable instance. */
$(".edit_trigger").bind("click", function() {
    $(this).prev().trigger("edit");
}); 

这篇关于可编辑-通过单击Y激活X的编辑的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆