因此,您需要处理被单击的“+”按钮,并进行 AJAX 调用。就像是:
http://jsfiddle.net/QE3xd/1/
HTML:
<input type="text" id="current" readonly="readonly" value="2" />
<input type="button" id="increaser" value="+" />
Javascript:
$(document).ready(function () {
$("#increaser").on("click", add);
});
function add() {
// Make AJAX call to PHP method (where DB operation is done)
$.ajax({
url: "/echo/json/",
cache: false,
data: {"increment_by": 1}, // This line may be unnecessary, as you could assume it increases the value by 1 every time (but using this could make it customizable
dataType: "json",
success: function (data) {
// Should return data in format: {"new_current": 4}
//$("#current").val(data.new_current);
// ^^ the real line
$("#current").val(+$("#current").val()+1);
// ^^ just to simulate the new number being returned
},
error: function () {
console.log("there was an error");
}
});
}