我有两个图像,需要在单击图像时进行切换。
<img id='arrowRotate' src='images/prof_arrow1.png' data-swap='images/prof_arrow.png'
data-src='images/prof_arrow1.png' />
用户单击图像时,src
应该获得的值,data-swap
而再次单击时,src
应更改为data-src
。这应该像切换一样继续发生。任何帮助表示赞赏。
$("#arrowRotate").click(function() {
var swapImage = $("#arrowGrey").attr("data-swap");
$("#arrowGrey").attr({
'src': swapImage,
id: 'arrowOrange'
});
});
这是我到目前为止所到的地方。
根据您对我的问题的理解,希望这是您所期望的,
$("#arrowRotate").click(function() {
var _this = $(this);
var current = _this.attr("src");
var swap = _this.attr("data-swap");
_this.attr('src', swap).attr("data-swap",current);
});
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句