jQuery来回更改图像 [英] jQuery change image back and forth
本文介绍了jQuery来回更改图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有以下html
<img id="voteImgBtn" onclick='editInstr(1);' src="http://site.com/sync.png" width="99" height="99" border="0" />
<script type="text/javascript">
function changeImage(a) {
document.getElementById("voteImgBtn").src=a;
}
</script>
然后,我点击并在ajax成功之后按如下方式更改图片
Then i change the image on click and after my ajax's success as follows
success: function(data){
changeImage( "http://site.com/syncD.png" );
}
我想做的是在changeImage之后有一个延迟,然后像这样放回旧图像:
What I want to do is have a delay after the changeImage and put back the old image like so:
success: function(data){
changeImage( "http://site.com/syncD.png" );
delay(500).changeImage( "http://site.com/sync.png" );
}
但是由于某些原因无法正常工作.你能给个建议怎么解决吗?
But for some reason that does not work. Could you give a suggestion how to fix it?
推荐答案
您的函数既不是可链接的也不是jQuery动画,这是delay()
唯一起作用的内容(更精确地说,.fx队列中的所有内容),尝试这样的事情:
Your function is neither chainable nor a jQuery animation, which is the only thing delay()
works on (anything in the .fx queue to be more precise), try something like this :
success: function(data){
changeImage( "http://site.com/syncD.png" );
setTimeout(function() {
changeImage( "http://site.com/sync.png" );
}, 500);
}
这篇关于jQuery来回更改图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文