好的,情况是这样的:
<div>
<a href=".." id=".."></a> //similarly multiple links
</div>当用户单击任何链接时,AJAX请求将其id作为GET变量传递。一旦成功,另一个<div>就会被一系列写有一些值的按钮填满。当用户单击按钮时,他可以通过在警告框中键入新值来更改按钮上写入的值。这也是由AJAX请求完成的。但是,一旦成功,数据库中的值就会更新,但更改后的值不会写回按钮。
$('#tags a').click(function(e){
e.preventDefault();
var send = $(this).attr('href');
$.ajax({
url:'getitemsfortag.php',
data:{tag:send},
type:'GET',
dataType:'html',
success:function(data){
$('#items').empty().append(data); //data contains list of buttons
},
error:function(xhr, status){
alert("Problem");
}
});
});
$("input[type='button']").live('click',function(){
var selected = $(this).attr("id");
var val = prompt("Enter new value",0);
$this = $(this);
$.ajax({
url:'updateCostItems.php',
data:{toupdate:selected, updatewith:val},
type:'GET',
dataType:'json',
success:function(json){
$this.val(json.update);
},
error:function(xhr, status){
alert("Problem");
}
});
});
});关于如何将更改后的值写回按钮有什么建议吗?
发布于 2011-06-03 19:52:07
$this.html(json.update);而不是
$(this).val(json.update);https://stackoverflow.com/questions/6226728
复制相似问题