我有这样的行数,
<tr class="row">
<td class="optionsImg">
<img src="../status/approved-01.png" />
<img src="../status/rejected-01.png" />
<img src="../status/pending-01.png" />
</td>
</tr>
和 JS,
$("#myTable").on('click', "optionsImg img", function () {
$(this).attr('src', this.src...);
});
我如何切换 approved-01 到 approved-02
或 approved-02 到 approved-01
和其他图像一样,我有两组图像,用 01.png 淡化一个完成,用 ..-02.png 淡化一个完成
最佳答案
试试这个:
$("#myTable").on('click', ".optionsImg img", function () {
var currentSRC = $(this).attr('src');
if(currentSRC.indexOf("-01")>-1)
{
currentSRC = currentSRC.replace("-01", "-02");
}
else
{
currentSRC = currentSRC.replace("-02", "-01");
}
$(this).attr('src', currentSRC );
});
关于javascript - 单击时切换 Img Src,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33387945/