-3

我有这个代码:

function EnableiPad(event) {
    var id = $(event.currentTarget).attr("data-id");
    var status = $(event.currentTarget).attr("data-status");    
    $.post("/Ipad/ChangeStatus", { id: id, enable: status }, onAjaxSuccess);
};
function onAjaxSuccess(data) {
    var status = $(".button-enable").attr("data-status");

    if (status == 'true') 
    {
        $('#statusImg').attr("src", '/Content/img/disable.png');
    }
    else 
    {
        $('#statusImg').attr("src", '/Content/img/enable.png');
    }
}

但它不会改变形象 -$('#statusImg').attr("src", '/Content/img/disable.png');

更新

这是我的图片:

@if (iPad.Enabled)
{
    <button  class="button-enable" data-original-title="Show timetable"  data-id="@iPad.Id" data-status="false" class="btn btn-mini" style="border: 0; background: transparent; box-shadow: none; padding: 0;">
        <img id="status" width="24" height="24" alt="Delete doctor" src="/Content/img/enable.png" />
    </button>
}
else
{ 
    <button id="statusDisable" class="button-enable" data-original-title="Show timetable"  data-id="@iPad.Id" data-status="true" class="btn btn-mini" style="border: 0; background: transparent; box-shadow: none; padding: 0;">
        <img id="status" width="24" height="24" alt="Delete doctor" src="/Content/img/disable.png" />
    </button>
}
4

1 回答 1

7

你的 img 标签的id是状态,所以它应该是:

$('#status').attr("src", '/Content/img/disable.png');
于 2012-08-10T08:01:09.830 回答