gpt4 book ai didi

php - 使用 HTML5 contenteditable javascript 和 PHP 进行内联编辑

转载 作者:行者123 更新时间:2023-11-28 18:33:38 24 4
gpt4 key购买 nike

我是 ajax 的新手,所以我想请求一个简单的 ajax 脚本来使用 HTML5 contenteditable="true"通过内联编辑来更新 mysql 数据库。

已经谷歌搜索但仍然不知道如何弄清楚。有人可以帮我提供一个 javascript 来更新数据库,甚至不用使用 javascript 的提交按钮。

我尽量不使用 jQuery,因为它会在 iPad 和手机上访问,即使我使用的是 twitter bootstrap

这是我的 html5

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Contact</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="description" content="">
<!-- Le styles -->
<link href="../assets/css/bootstrap.css" rel="stylesheet">
<link href="../assets/css/bootstrap-responsive.css" rel="stylesheet">
<link href="../assets/js/google-code-prettify/prettify.css" rel="stylesheet">
<style>
body {
padding-top: 60px; /* 60px to make the container go all the way to the bottom of the topbar */
}
</style>
<!-- HTML5 shim, for IE6-8 support of HTML5 elements -->
<!--[if lt IE 9]>
<script src="http://html5shim.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
<script src="../assets/js/jquery.js"></script>
<script src="../assets/js/bootstrap.min.js"></script>
<script src="../assets/js/google-code-prettify/prettify.js"></script>
<!-- Fav and touch icons -->
<link rel="shortcut icon" href="../assets/ico/favicon.ico">
<link rel="apple-touch-icon-precomposed" sizes="144x144" href="../assets/ico/apple-touch-icon-144-precomposed.png">
<link rel="apple-touch-icon-precomposed" sizes="114x114" href="../assets/ico/apple-touch-icon-114-precomposed.png">
<link rel="apple-touch-icon-precomposed" sizes="72x72" href="../assets/ico/apple-touch-icon-72-precomposed.png">
<link rel="apple-touch-icon-precomposed" href="../assets/ico/apple-touch-icon-57-precomposed.png">
</head>

----
----
<div class="contact">
<form class="form-horizontal" method="POST" action="updatecontactmaininfo.php">
<?php
$sql=mysql_query("select * from contacts where SupplierId='$compid'");
$dt=mysql_fetch_array($sql);
?>
<table class="table table-bordered table-hover table-striped ">
<tr>
<td><i class="icon-user"></i> ID:</td>
<td><input type="text" name="SupplierId" value="<?=$dt[SupplierId]?>"></td>
<td><i class="icon-briefcase"></i> Company:</td>
<td><input type="text" name="CompanyName" value="<?=$dt[CompanyName]?>"></td>
</tr>
<tr>
<td><i class="icon-home"></i> Address:</td>
<td colspan="3"><input type="text" name="Address1" value="<?=$dt[Address1]?>"></td>
</tr>
<tr>
<td><i class="icon-map-marker"></i> City:</td>
<td><input type="text" name="City" value="<?=$dt[City]?>"></td>
<td><i class="icon-map-marker"></i> State:</td>
<td><input type="text" name="State" value="<?=$dt[State]?>"></td>
</tr>
<tr>
<td align="right" class="tdblue"><i class="icon-flag"></i> Country:</td>
<td><input type="text" name="Country" value="<?=$dt[Country]?>"></td>
<td align="right" class="tdblue"><i class="icon-envelope"></i> Zip:</td>
<td><input type="text" name="State" value="<?=$dt[ZipCode]?>"></td>
</tr>
<tr>
<td><i class="icon-volume-up"></i> Phone:</td>
<td><input type="text" name="Phone" value="<?=$dt[Phone]?>"></td>
<td><i class="icon-print"></i> Fax:</td>
<td><input type="text" name="Fax" value="<?=$dt[Fax]?>"></td>
</tr>
<tr>
<td><i class="icon-globe"></i> Website:</td>
<td><input type="text" name="website" value="<?=$dt[website]?>"></td>
<td><i class="icon-adjust"></i> Zone:</td>
<td><input type="text" name=Zone"" value="<?=$dt[Zone]?>"></td>

<input type="hidden" name="RecId" value="<?=$dt[RecId]?>">
<input type="hidden" name="limit" value="<?=$limit?>">
</tr>
</table>
</div>

我的 PHP (updatecontactmaininfo.php) 是:

<?php
include("../config.php");

$SupplierId = $_POST[SupplierId];
$CompanyName = $_POST[CompanyName];
$Address1 = $_POST[Address1];
$City = $_POST[City];
$State = $_POST[State];
$Country = $_POST[Country];
$ZipCode = $_POST[ZipCode];
$Phone = $_POST[Phone];
$Fax = $_POST[Fax];
$website = $_POST[website];
$Zone = $_POST[Zone];
$RecId = $_POST[RecId];
$limit = $_POST[limit];

mysql_query("update contacts set SupplierId='$SupplierId', Address1='$Address1', City='$City', State='$State', Country='$Country', ZipCode='$ZipCode', Phone='$Phone', Fax='$Fax', website='$website' where RecId='$RecId'");

header('Location:contactsform.php?limit='.$limit);

?>

谢谢。

最佳答案

您可以将 event oninput 附加到 contenteditable

var el = document.getElementById('element_id')
el.oninput = function(){
// you can grab values of other inputs and send ajax call here
}

关于php - 使用 HTML5 contenteditable javascript 和 PHP 进行内联编辑,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13509615/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com