我想知道如何使用JQuery重新创建按下按钮的效果。
我的想法是在哪里使用鼠标单击事件将图像更改为按下的图像,然后在释放鼠标后返回到原始图像。你对我可以实现这一点有什么想法或想法?
发布于 2013-07-18 07:35:10
这应该行得通。代码为:
$("#button").mousedown(function(){
$("#img").attr("src", "img2.jpg");
})
$("#button").mouseup(function(){
$("#img").attr("src", "img1.jpg");
}希望这能有所帮助!
发布于 2013-07-18 07:35:01
让图像侦听单击事件并更改图像的来源。
$('img').on('click', function() {
var $this = $(this);
$this.attr('src', function(i, src) {
return src === 'something' ? 'somethingelse' : 'something' ;
});
});发布于 2013-07-18 07:38:17
你到底想要什么?像这样的事情就是……
$('btn-img').click(function(){
var img = $(this).children('img'); // return object of inner img
// your event on current img with click
}).mouseleave(function(){
// other event on mouseleave
});Html:
<a class="btn-img">
<img src="yourImage.jpg" />
</a>https://stackoverflow.com/questions/17712029
复制相似问题