Tho*_*ian 2 javascript jquery toggle src attr
我有两个图像,我需要切换点击图像.
<img id='arrowRotate' src='images/prof_arrow1.png' data-swap='images/prof_arrow.png'
data-src='images/prof_arrow1.png' />
Run Code Online (Sandbox Code Playgroud)
当用户单击图像时,src应该获取值,data-swap当您再次单击时,src应该更改为data-src.这应该像切换一样继续发生.任何帮助赞赏.
$("#arrowRotate").click(function() {
var swapImage = $("#arrowGrey").attr("data-swap");
$("#arrowGrey").attr({
'src': swapImage,
id: 'arrowOrange'
});
});
Run Code Online (Sandbox Code Playgroud)
这是我到目前为止的地方.
根据我对你问题的理解,希望这是你期望的那个,
$("#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);
});
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
84155 次 |
| 最近记录: |