Я в настоящее время использую этот код фрагмента, который я схватил из некоторого сообщения stackoverflow,
Он преобразует элемент span для ввода, поэтому я могу редактировать и возвращаться к диапазону после
как я могу сделать так, чтобы, когда входные данные преобразуются обратно в диапазон, он обновляет свое значение в базе данных mysql?
/**
We're defining the event on the 'body' element,
because we know the 'body' is not going away.
Second argument makes sure the callback only fires when
the 'click' event happens only on elements marked as 'data-editable'
*/
$('body').on('click', '[data-editable]', function() {
var $el = $(this);
var $input = $('<input/>').val($el.text());
$el.replaceWith($input);
var save = function() {
var $p = $('<span data-editable />').text($input.val());
$input.replaceWith($p);
};
/**
We're defining the callback with 'one', because we know that
the element will be gone just after that, and we don't want
any callbacks leftovers take memory.
Next time 'p' turns into 'input' this single callback
will be applied again.
*/
$input.one('blur', save).focus();
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
Click on <span data-editable> EDIT</span>
Вы должны обращаться с ним в функции save
/**
We're defining the event on the 'body' element,
because we know the 'body' is not going away.
Second argument makes sure the callback only fires when
the 'click' event happens only on elements marked as 'data-editable'
*/
$('body').on('click', '[data-editable]', function() {
var $el = $(this);
var $input = $('<input/>').val($el.text());
$el.replaceWith($input);
var save = function() {
var $p = $('<span data-editable />').text($input.val());
$input.replaceWith($p);
// AJAX call to your backend to save $input.val()
};
/**
We're defining the callback with 'one', because we know that
the element will be gone just after that, and we don't want
any callbacks leftovers take memory.
Next time 'p' turns into 'input' this single callback
will be applied again.
*/
$input.one('blur', save).focus();
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
Click on <span data-editable> EDIT</span>