jQuery jeditable trigger on click

南笙酒味 提交于 2019-12-07 15:44:58

问题


I need to use inline edit in my application. For this purpose I am using the Jeditable plugin for jQuery.

I want to trigger editable mode for an element only when I click on it. This is my code which doesn't work:

var tet = "";
$(".edit-client").click(function(event) {
    tet = "#"+event.target.id;
    //alert(tet);
});

$(tet).editable("/bestcredit/admin.php/request/editClient", {
    submitdata : function (value,settings){
                    return {"Client[id]":'.$model->client->id.' };
                },

    //indicator : "Saving...",
    //tooltip   : "Click to edit...",
    submit   : "OK",
    name : "Client["+tet.substr("1")+"]"
    //alert(1);
 }); 

How can I add this functionality?


回答1:


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>

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");
});


来源:https://stackoverflow.com/questions/11952196/jquery-jeditable-trigger-on-click

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!