Javascript在内容页面中不起作用 [英] Javascript Not Working In Content Page

查看:103
本文介绍了Javascript在内容页面中不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

< asp:Content ID =Content1ContentPlaceHolderID =ContentPlaceHolder1Runat =Server>





< table class =style1> < asp:Image ID =img1runat =serverImageUrl =/ Sample-Slide / slide / 1.jpgWidth =100% />



< script language =javascripttype =text / javascript >

var i = 1;

函数fun(){



i ++;

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

if(i == 5){

i = 0;

}

}

setInterval(fun(),4000);

< / script>





以上javascript在示例网页表格中正常工作但不在内容页面或在母版页面......



你知道......

解决方案

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


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



它适用于你。


< blockquote>使用



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";


这篇关于Javascript在内容页面中不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆