且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Javascript在内容页面中不起作用

更新时间:2023-11-13 22:28:34

我很确定您的控件ID不正确(在使用母版页时会更新它们),请使用firebug进行检查; - )


javascript中内容页面中的图像ID应该是运行时间ID。运行你的页面并查看视图页面源并选择图像的id并用代码编写。



它适用于你。


使用



document.getElementById(<%= img1.ClientID%>)。src =/ Sample-Slide / slide /+ i +.jpg;


<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">


<asp:Image ID="img1" runat="server" ImageUrl="/Sample-Slide/slide/1.jpg" Width="100%" />

<script language="javascript" type="text/javascript">
var i = 1;
function fun() {

i++;
document.getElementById("img1").src = "/Sample-Slide/slide/" + i + ".jpg";
if (i == 5) {
i = 0;
}
}
setInterval("fun()", 4000);
</script>


The above javascript working in properly in a sample webform but not in content page or in master page...

Thnkg you...

I'm pretty sure that your control ID is not correct (they are updated when working with master page), check these with firebug ;-)


the image id within content page in javascript should be run time id. run your page and see view page source & pick that id of image & write in code.

it will work for u.


Use

document.getElementById("<%= img1.ClientID %>").src = "/Sample-Slide/slide/" + i + ".jpg";