我正在尝试延迟 jQuery 序列,但拒绝工作。
var old = $('.likes' + id).text();
$('.likes' + id).text("You've already voted").delay(3000).text(old);
现在,旧文本会立即输入,而不会显示“您已经投票”。
有什么建议么?
编辑:
按照要求:
HTML:
<li>
<h2><a href="?page=dub&id=%%DUB_ID%%">%%DUB_TITLE%%</a></h2>
<div class="dub">
<iframe width="560" height="315" src="http://www.youtube.com/embed/%%YOUTUBE_ID%%?hd=1" frameborder="0" allowfullscreen></iframe>
<div id="conten_wrapper">
<div id="conten_meta">
<p> Posted by: <a href="?page=profile&id=%%USER_ID%%">%%USERNAME%%</a><br />
Likes: <span class="likes%%DUB_ID%%">%%LIKES%%</span><br />
Date posted: %%DATE%%
</p>
</div>
<div id="conten_social">
<a href="javascript:void(0);" onclick="javascript:makeRequest(\'like\', %%DUB_ID%%)" class="likebtn">Like</a><a href="javascript:void(0);" onclick="javascript:makeRequest(\'dislike\', %%DUB_ID%%)" class="likebtn2">Dislike</a>
</div>
</div>
</div>
</li>
js:
function makeRequest(name, id){
$.ajax({
type: "GET",
url: "ajax.php",
data: "name=" + name + "&id=" + id,
success: function(msg){
var obj = jQuery.parseJSON(msg);
if(obj.status == "SUCCES"){
$('.likes' + id).html(parseInt($('.likes' + id).html(), 10)+1);
}else {
var old = $('.likes' + id).text();
$('.likes' + id).text("You've already voted").delay(3000).text(old);
}
}
});
}