Javascript
$(document).ready(function() {
var originaltext = $('#editable').val()
$("#editable").keydown(function(e){
if(e.which == 9)
{
var content = $('#editable').val();
var originaltext = $('#editable').val();
$.ajax({
url: 'save.php',
type: 'POST',
data:{
content: content
},
success:function (data) {
if (data == '1')
{
$("#status")
.addClass("success")
.html("Data saved successfully")
.fadeIn('fast')
.delay(3000)
.fadeOut('slow');
}
else
{
$("#status")
.addClass("error")
.html("An error occured, the data could not be saved")
.fadeIn('fast')
.delay(3000)
.fadeOut('slow');
}
}
});
}
});
$("#editable").click(function (e) {
$("#save").show();
e.stopPropagation();
});
$(document).click(function() {
$("#save").hide();
$('#editable').value = originaltext;
});
});
当我在文本框外单击时,我希望文本字段恢复更改。它将恢复到数据库中的保存文本
我试过这个
$(文档).click(函数() {
$("#save").hide();
$('#editable').value = originaltext;
});
但它没有用,我该怎么办?
HTML
<div id="status"></div>
<?php
//get data from database.
include("db.php");
$sql = mysql_query("select * from test where ID= '1'");
$row = mysql_fetch_array($sql);
?>
<input id="editable" name="editable" type="text" value="<?php echo $row['Name'];?>">
<button id="save">Save</button>
</div>
</div>