现在我的页面包含一组字段和可编辑的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>
但它不能正常工作:当我按字段点击,输入新值并按“输入”然后该字段将其值更改为“单击以编辑”,但我需要该字段继续显示更新的值。我该怎么做?我应该改变什么?
答案 0 :(得分:0)
在你的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();