我无法使用Masterpage制作幻灯片脚本。 下面一个工作正常,现在我需要转换为使用MasterPage的ASPX项目。
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<script language="javascript" type="text/javascript">
var i = 1;
function fun() {
i++;
document.getElementById("img1").src = "images/" + i + ".jpg";
if (i == 2) //here 2 is number of images i want to display in the slide show
{ i = 0; }
}
setInterval("fun()", 4000);
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Image ID="img1" runat="server" src="images/1.jpg" Height="500px" Width="1000px" />
</div>
</form>
</body>
</html>
这是我尝试过的。母版
<%@ Master Language="C#" AutoEventWireup="true" CodeFile="Main.master.cs" Inherits="Main" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<script language="javascript" type="text/javascript">
var i = 1;
function fun() {
i++;
document.getElementById("img1").src = "images/" + i + ".jpg";
if (i == 2) //here 2 is number of images i want to display in the slide show
{ i = 0; }
}
setInterval("fun()", 4000);
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:ContentPlaceHolder id="ContentPlaceHolder1" runat="server">
</asp:ContentPlaceHolder>
</div>
</form>
</body>
</html>
以下是从我的母版页页派生的Aspx代码。
<%@ Page Title="" Language="C#" MasterPageFile="~/Main.master" AutoEventWireup="true" CodeFile="Default2.aspx.cs" Inherits="Default2" %>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
<asp:Image ID="img1" runat="server" src="images/1.jpg" Height="500px" Width="1000px" />
</asp:Content>
请告诉我。
答案 0 :(得分:0)
试试这个:
document.getElementById("<%# img1.ClientID %>").src = "images/" + i + ".jpg";
答案 1 :(得分:0)
试试这个
MAster Page
<%@ Master Language="C#" AutoEventWireup="true" CodeFile="Main.master.cs" Inherits="Main" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<asp:ContentPlaceHolder ID="head" runat="server">
</asp:ContentPlaceHolder>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:ContentPlaceHolder id="ContentPlaceHolder1" runat="server">
</asp:ContentPlaceHolder>
</div>
</form>
</body>
</html>
内容页面
<%@ Page Title="" Language="C#" MasterPageFile="~/Main.master" AutoEventWireup="true" CodeFile="Default2.aspx.cs" Inherits="Default2" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
<script type="text/javascript">
var i = 1;
function fun() {debugger;
i++;
document.getElementById("<%=img1.ClientID%>").src = "images/" + i + ".jpg";
if (i == 2) //here 2 is number of images i want to display in the slide show
{ i = 0; }
}
setInterval("fun()", 4000);
</script>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
<asp:Image ID="img1" runat="server" src="images/1.jpg" Height="500px" Width="1000px" />
</asp:Content>