Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/394.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 单击时切换Img Src_Javascript_Jquery - Fatal编程技术网

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 );
    });