我想从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