Javascript 单击时切换Img Src
我有很多这样的行Javascript 单击时切换Img Src,javascript,jquery,Javascript,Jquery,我有很多这样的行 <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
<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>
如何切换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 );
});
当您想要切换它时?可能重复
$("#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 );
});