[英]Toggle Img Src on click
我有這樣的行數,
<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 to approved-02
切換approved-01 to approved-02
或approved-02 to 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 );
});
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.