我想從javascript設置asp圖像元素src屬性,但是url屬性未設置。從javascript設置asp圖像src屬性
function slideshow() {
$.ajax({
type: "POST",
contentType: "application/json; charset=utf-8",
url: "/RollingScreen.aspx/GetNextImage",
dataType: "json",
data: "{}",
success: function (data) {
//this changes the image on the web page
$('#imgSlideShow').attr("src","~/1.png");
$("#txt1").val(data.d);
//fires another sleep/image cycle
setTimeout(slideshow,5000);
},
error: function (result) {
alert(result.message);
}
});
}
$(document).ready(function() {
//Kicks the slideshow
slideshow();
});
我的aspx圖像元素是
<asp:Image ID="imgSlideShow" runat="server" Height="300px" Width="600px" ImageAlign="Middle" ImageUrl="~/1.png"/>....
誰能幫我...
圖像ID在呈現時不是imgSlideShow。查看源代碼或檢查元素以查看ID是什麼,或者使用CssClass爲它提供一個類名,您可以使用它來引用它。此外,你不能在JavaScript中使用〜只在.Net – Archer