admin管理员组文章数量:1315986
I have this code:
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');
}
}
But it doesn't change image - $('#statusImg').attr("src", '/Content/img/disable.png');
Update
Here is my images:
@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>
}
I have this code:
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');
}
}
But it doesn't change image - $('#statusImg').attr("src", '/Content/img/disable.png');
Update
Here is my images:
@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>
}
Share
Improve this question
edited Aug 10, 2012 at 7:52
Tim B James
20.4k4 gold badges76 silver badges106 bronze badges
asked Aug 10, 2012 at 7:42
revolutionkpirevolutionkpi
2,68211 gold badges49 silver badges87 bronze badges
5
- you missed the last bracket. Is the actual code like that or this is just a typo? – davids Commented Aug 10, 2012 at 7:45
-
1
This calls for basic debugging first. At which point does it fail - is
EnableiPad()
ever called? Is the Ajax request ever fired? Does the success callback ever e back? Are there any error messages in the console? – Pekka Commented Aug 10, 2012 at 7:45 - It seems valid. Probably the problem is in something subtle. – Lyubomir Vasilev Commented Aug 10, 2012 at 7:46
-
Any errors? Why are you handling the image change in the callback function when you don't seem to use the
data
from the callback? why not just do it prior to thepost
event? – Tim B James Commented Aug 10, 2012 at 7:47 -
$('#statusImg').attr("src", '/Content/img/disable.png');
should work fine if selector is ok. Try to debug app more. – Michael Commented Aug 10, 2012 at 7:47
1 Answer
Reset to default 7id of your img tag is status, so it should be:
$('#status').attr("src", '/Content/img/disable.png');
本文标签: cChange image src with jqueryStack Overflow
版权声明:本文标题:c# - Change image src with jquery - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741963865a2407433.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论