如何在JEditable/JQuery中保存事件后字段的更新值

How to save updated value from field after event in JEditable/JQuery?

本文关键字:事件 字段 更新 保存 JEditable JQuery      更新时间:2023-09-26

现在我的页面包含一组字段和用于编辑的JEditable脚本:

<html>
<head>
    <script type="text/javascript" src="jquery-1.7.2.min.js"></script>
    <script type="text/javascript" src="jquery.jeditable.js"></script>
</head>
<body>
    <table border='1'>
    <div id="load-button" style="border:1px solid black; background-color:white;padding:5px;cursor:pointer;width:200px;text-align:center;border-radius:4px;">Load button</div>
    <script type="text/javascript" charset="utf-8">
        $(function() {
          $(".field").editable("echo.php", { 
                indicator : "<img src='img/indicator.gif'>",
                tooltip   : "Move mouseover to edit...",
                event     : "mouseover",
                style  : "inherit"
          });  
        });
    </script>
    <?php
        mysql_connect('localhost', 'root','') or die('connect');
        mysql_select_db('jquery_test') or die('select_db');
        $query=mysql_query('SELECT * FROM labels');
        while ($data=mysql_fetch_assoc($query))
        {
            echo '<b class="field" style="display: inline">'.$data['text'].'</b><br >';
        }
    ?>

</body>
</html>

但它无法正常工作:当我按字段单击时,输入新值并按"输入",然后字段将其值更改为"单击以编辑",但我需要字段继续显示更新的值。我该怎么做?我应该更改什么?

在你的jQuery代码中,我有这样的东西 - .fnUpdate才是真正的关键部分......

var tableElement = $(".field");
tableElement.editable("echo.php", { 
            style : "inherit",
            "callback": function(sValue,y){
                    //Grab the cell position
                    var aPos = tableElement.fnGetPosition(this);
                    tableElement.fnUpdate(sValue, aPos[0], aPos[1]);
            },{
              "submitdata" : "OK"
 });
 tableElement.fnDraw();