[英]Inline editing using HTML5 contenteditable javascript and PHP
我是ajax的新手,所以我想問一個簡單的ajax腳本,以使用HTML5 contenteditable =“ true”進行內聯編輯來更新mysql數據庫。
已經在四處搜尋,但仍然不知道如何解決。 有人可以幫我給一個javascript更新數據庫,甚至不用javascript提交按鈕。
我嘗試不使用jQuery,因為它將在iPad和手機上訪問,甚至以為我正在使用twitter引導程序
這是我的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
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.