【发布时间】:2015-12-07 13:25:28
【问题描述】:
我创建了可编辑的动态 html 表,双击文本用户可以更改它,但更改是临时的,我也希望将其保存在数据库中。
我的表格代码是 (@jsfiddle)
html表格
<table class="editableTable table table-striped table-bordered">
<thead>
<tr>
<th> A </th>
<th> B </th>
<th> C </th>
<th> D </th>
</tr>
</thead>
<tbody>
<?php
$sql=" SELECT * from orderid";
$result = mysqli_query($con, $sql);
if(mysqli_num_rows($result)>0)
{
while($row = mysqli_fetch_assoc($result))
{?> <tr>
<td> <? echo $row['a']; ?> </td>
<td> <? echo $row['b']; ?> </td>
<td> <? echo $row['c']; ?> </td>
<td> <? echo $row['d']; ?> </td>
</tr>
<?}
}?>
</tbody>
</table>
脚本代码
$(function ()
{
$("td").dblclick(function ()
{
var OriginalContent = $(this).text();
$(this).addClass("cellEditing");
$(this).html("<input type='text' value='" + OriginalContent + "' />");
$(this).children().first().focus();
$(this).children().first().keypress(function (e)
{
if (e.which == 13)
{
var newContent = $(this).val();
$(this).parent().text(newContent);
$(this).parent().removeClass("cellEditing");
}
});
$(this).children().first().blur(function()
{
$(this).parent().text(OriginalContent);
$(this).parent().removeClass("cellEditing");
});
});
});
我希望用来编辑条目的代码是
$sql1="UPDATE tablename set A='".$a."', B= '".$b."', C= '".$c."', D= '".$d."' WHERE id='".$id."' ";
if(!mysqli_query($con,$sql1))
{
die('Error:' . mysqli_error($con));
}
表格视图
id A B C D
1 a b c d
谁能告诉我如何在数据库中保存新条目
【问题讨论】:
-
您可以调用api将数据保存到数据库中
-
您可以使用 ajax 然后在点击事件时将数据保存在数据库中
-
@Rohit Azad 你能告诉我怎么做吗
-
添加一个保存按钮,点击后在一个带有更新代码的 php 页面上向您的服务器发出 ajax 发布请求。
-
@lyra 现在是先生。 Thanasis Grammatopoulos 这样做
标签: javascript jquery html mysql ajax