2009-08-18 58 views
2

我一直在寻找一个非常好的,有据可查的jquery插件,它可以让我通过单击另一个按钮来编辑值。使用Jeditable保存编辑值

Jeditable是我找到的最接近的,但我不知道如何让它保存,即使在测试。快速返回值的东西。

我用这对我的PHP脚本:

function editprofile() 
{ 
    $this->input->post('value'); 
} 

这是我的JS脚本:

$("a.edit").live('click', function(){ 

    $(this).parent("li").find("span.detail").editable('profile/editprofile', 
    { 
     indicator : 'Saving...', 
     submit : 'OK', 
     tooltip : 'Click to edit...' 
    });  
}); 

这是我的HTML:

<span id="city" class="detail">Philadelphia</span> 
<a href="javascript:;" class="edit">Edit</a> 

修正: 应该PHP成为:

echo $this->input->post('value'); 
+0

您可以扩展服务器端代码吗? – voyager 2009-08-18 19:38:05

回答

3

Jeditable

从Jeditable的例子:

在这个例子中load.php应该返回未呈现的XHTML标记源。不过save.php应该返回呈现的xhtml。保存浏览器时将显示保存脚本返回的内容。还有另一种选择。您可以在数据参数中传递标记源。

所以save.php应该返回(打印到页)文本(而不是HTML),它会在编辑的地方进行显示。它还应该将更改保存在数据库或您应该执行的任何其他服务器端工作中。

You post with javascript, and echo to the client the response. http://img34.imageshack.us/img34/3412/savephp.png

save.php你做任何你存储新值。

这里有另一个tutorial for the in-line editor for jQuery

+0

前2个链接是我找到的2个,我正在使用第一个链接,并且该教程留下了我不确定该怎么做的部分,这是php的一个方面。 – matthewb 2009-08-18 19:36:02

+0

你是对的,有点急于那里。 – voyager 2009-08-18 19:37:11

+0

我想我明白了:忘了一个字 对我的php函数 echo $ this-> input-> post('value'); – matthewb 2009-08-18 19:42:05

1

toggledit有一个简单的回调机制(onpreview,onedit)和一个简单的公共方法api(编辑,预览)。

要保存,您需要编写自己的ajax函数,以便在触发这些或其他某些事件时触发。如果保存按钮被点击。

切换到编辑模式的听众也配置 - 你可以在你的按钮选择传:

 
$(el).toggleEdit('edit'); 
$(el).toggleEdit('preview'); 

 
$(form).find('input,select').toggleEdit({ 
    listeners: { 
     edit: '#your_button' 
    } 
}); 

此外,您可以使用公共事件手动触发从您的按钮编辑和预览

请参阅https://stackoverflow.com/questions/708801/whats-the-best-edit-in-place-plugin-for-jquery/:>