1

您好我正在使用以下脚本更改按钮图像以在播放和停止之间切换:

<input type="image" src="../../Content/images/play.png" name="btn" style="width:22; height:22;"  />
   $(document).ready(function () {
            $('#btn').bind("click", function () {
                if ($(this).attr("scr") == "../../Content/images/play.png")
                    $(this).attr("scr", "../../Content/images/puase.png");
                else
                    $(this).attr("scr", "../../Content/images/play.png");
            });
        });

它不起作用,将感谢您的建议。

4

2 回答 2

1

你应该使用

$('input[name=btn]').bind("click", function () {

并更改scrsrc

于 2012-08-30T23:23:33.627 回答
0

试试这个:

$(document).ready(function () {
    var is_play = true;

    $('#btn').click(function () {
        if (is_play){
            is_play  = false;
            $(this).attr("src", "../../Content/images/puase.png");
        }
        else{
            $(this).attr("src", "../../Content/images/play.png");
            }
    });
});

还添加id="btn"到:

<input type="image" id="btn" src="../../Content/images/play.png" name="btn" style="width:22; height:22;"  />
于 2012-08-30T23:24:11.167 回答