单击时切换Img Src

时间:2015-10-28 09:59:24

标签: 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>

和JS,

    $("#myTable").on('click', "optionsImg img", function () {
        $(this).attr('src', this.src...);
    });

我如何为其他图片切换approved-01 to approved-02approved-02 to approved-01和相同,我有两组图像,01.png淡化一个完成,用..- 02.png <淡化一个/ p>

1 个答案:

答案 0 :(得分:2)

试试这个:

$("#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 );
    });