当页面加载时,我有一个初始 replaceWith 运行以下代码:
<span id="requestAlert>"
<span class="font1">wants to be your friend </span>
<input type="submit" id="acceptRequest" value="Accept" style="width: 60px;
height: 28px" class="button1" />
<input type="submit" id="denyRequest" value="Deny" style="width: 50px;
height: 28px" class="button1" />
</span>
然后我有以下代码,假设在页面完成加载时操作上面的代码:
$("#acceptFriend").live('click', function() {
acceptFriend();
});
function acceptFriend() {
var targetedUserId = $(document).getUrlParam("id");
jQuery.ajax({
type: "POST",
dataType: "JSON",
url: "<?=base_url()?>index.php/regUserDash/acceptFriend",
data: { targetedUserId: targetedUserId },
json: {acceptFriendSuccess: true},
success: function(data) {
if(data.acceptFriendSuccess == true) {
$("#requestAlert").replaceWith('<span class="font1">You two are noe friends</span>');
}
}
});
}
我似乎无法获得上述代码来操作初始 replaceWith 代码。我想也许 .live() 可以解决问题,但显然不是。关于为什么它不起作用的任何想法?有什么解决办法吗?