图片轮换第五张显示不了

xtxychc 2011-02-11 03:43:36
script language="javascript" type="text/javascript">
var imgWidth = 320; //图片宽
var imgHeight = 211; //图片高
var textFromHeight = 21; //焦点字框高度 (单位为px)
var textStyle = "whiter"; //焦点字class style (不是连接class)
var textLinkStyle = "whiter"; //焦点字连接class style
var buttonLineOn = "#f60"; //button下划线on的颜色
var buttonLineOff = "#000"; //button下划线off的颜色
var TimeOut = 1000; //每张图切换时间 (单位毫秒);
var imgUrl = new Array();
var imgLink = new Array();
var imgtext = new Array();
var imgAlt = new Array();
var adNum = 0;
//焦点字框高度样式表 开始
document.write('<style type="text/css">');
document.write('#focuseFrom{width:' + (imgWidth + 2) + ';margin: 0px; padding:0px;height:' + (imgHeight + textFromHeight) + 'px; overflow:hidden;}');
document.write('#txtFrom{height:' + textFromHeight + 'px;line-height:' + textFromHeight + 'px;width:' + imgWidth + 'px;overflow:hidden;}');
document.write('#imgTitle{width:' + imgWidth + ';top:-' + (textFromHeight + 14) + 'px;height:18px}');
document.write('</style>');
document.write('<div id="focuseFrom">');
</script>
...全文
186 10 打赏 收藏 转发到动态 举报
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
fashionmyself 2011-02-11
  • 打赏
  • 举报
回复
[Quote=引用 8 楼 hualilihua 的回复:]
写这么多js干嘛啥 用Flash吧!
[/Quote]赞同,直接用Flash就是了
ChinaXtHuLang 2011-02-11
  • 打赏
  • 举报
回复
有点错误。改了下:
/// <summary>
/// Flash幻灯片
/// </summary>
/// <param name="oNum">显示数量</param>
/// <returns></returns>
public string strFlash(string oNum)
{
string TopNum = " Top " + oNum + " ";
string strCode = null;
string oFlashPic = "";
string oFlashLink = "";
string oFlashTitle = "";
SqlConnection myConn = DB.GetConnection();
string strSql = "Select " + TopNum + " ID,PicName,PicLink,PicImg From Pic Order By Id Desc";
SqlDataAdapter da = new SqlDataAdapter(strSql, myConn);
myConn.Open();
DataSet ds = new DataSet();
da.Fill(ds, "myTable");
DataTable dt = ds.Tables[0];
strCode += "<script language=\"javascript\" type=\"text/javascript\">\r\n";
strCode += " var swf_width = 300;\r\n";
strCode += " var swf_height = 240;\r\n";
strCode += " var swf_path = '';\r\n";
strCode += " var files = '';\r\n";
strCode += " var texts = '';\r\n";
strCode += " var links = '';\r\n\r\n";
foreach (DataRow row in dt.Rows)
{
oFlashPic += row["PicImg"].ToString() + "|";
oFlashLink += row["PicLink"].ToString() + "|";
oFlashTitle += row["PicName"].ToString() + "|";
}

S_Pic = oFlashPic.Substring(0, oFlashPic.LastIndexOf("|"));
S_Title = oFlashTitle.Substring(0, oFlashTitle.LastIndexOf("|"));
S_Link = oFlashLink.Substring(0, oFlashLink.LastIndexOf("|"));
strCode += " files += '" + S_Pic + "';\r\n";
strCode += " texts += '" + S_Title + "';\r\n";
strCode += " links += '" + S_Link + "';\r\n\r\n";

strCode += " document.write('<object classid=\"clsid:d27cdb6e-ae6d-11cf-96b8-444553540000\" codebase=\"http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0\" width=\"' + swf_width + '\" height=\"' + swf_height + '\">');\r\n";
strCode += " document.write('<param name=\"movie\" value=\"' + swf_path + 'images/bcastr31.swf\">');\r\n";
strCode += " document.write('<param name=\"quality\" value=\"high\">');\r\n";
strCode += " document.write('<param name=\"menu\" value=\"false\">');\r\n";
strCode += " document.write('<param name=\"wmode\" value=\"opaque\">');\r\n";
strCode += " document.write('<param name=\"FlashVars\" value=\"bcastr_file=' + files + '&bcastr_link=' + links + '&bcastr_title=' + texts + '&TitleBgColor=6699FF\">');\r\n";
strCode += " document.write('<embed src=\"' + swf_path + 'images/bcastr31.swf\" wmode=\"opaque\" FlashVars=\"bcastr_file=' + files + '&bcastr_link=' + links + '&bcastr_title=' + texts + '&TitleBgColor=6699FF&\" menu=\"false\" quality=\"high\" width=\"' + swf_width + '\" height=\"' + swf_height + '\" type=\"application/x-shockwave-flash\" pluginspage=\"http://www.macromedia.com/go/getflashplayer\" />');\r\n";
strCode += " document.write('</object>');\r\n";
strCode += "</script>\r\n";
myConn.Close();
return strCode;
}


已测试。。。
测试截图:
回头是岸 2011-02-11
  • 打赏
  • 举报
回复
写这么多js干嘛啥 用Flash吧!
xtxychc 2011-02-11
  • 打赏
  • 举报
回复
aspx.cs中的代码
void bind()
{
using (SqlConnection connection = new SqlConnection(@"server=127.0.0.1;database=jx_wz;uid=sa;pwd=sa" ))
{
SqlDataAdapter sda = new SqlDataAdapter("select top 5 * from images order by imageid desc", connection);
DataSet ds = new DataSet();
DataTable dt = new DataTable();
sda.Fill(ds);
dt = ds.Tables[0];
for (int i = 0; i < dt.Rows.Count; i++)
{
imgUrl += dt.Rows[i]["imgUrl"].ToString() + ",";
imgtext += dt.Rows[i]["imgText"].ToString() + ",";
imgLink += dt.Rows[i]["imgLink"].ToString() + ",";
imgAlt += dt.Rows[i]["imgAlt"].ToString() + ",";
}
}
xtxychc 2011-02-11
  • 打赏
  • 举报
回复
 focustext.innerHTML = imgtext[adNum]; //在图片 下 面 显 示 路径
theTimer = setTimeout("nextAd()", TimeOut);
}
document.write('<a target=_self href="javascript:goUrl()"><img style="FILTER: revealTrans(duration=1,transition=5);" width=' + imgWidth + ' height=' + imgHeight + ' border=0 vspace="0" name=imgInit class="imgClass"></a><br>');
document.write('<div id="txtFrom"><span id="focustext" class="' + textStyle + '"></span></div>');
document.write('<div id="imgTitle">');
document.write(' <div id="imgTitle_down"> <a class="trans"></a>');
//数字 按钮 代 码开始
focustext.innerHTML = imgtext[adNum]; //在图 片下 面 显 示 路径
theTimer = setTimeout("nextAd()", TimeOut);
}
document.write('<a target=_self href="javascript:goUrl()"><img style="FILTER: revealTrans(duration=1,transition=5);" width=' + imgWidth + ' height=' + imgHeight + ' border=0 vspace="0" name=imgInit class="imgClass"></a><br>');
document.write('<div id="txtFrom"><span id="focustext" class="' + textStyle + '"></span></div>');
document.write('<div id="imgTitle">');
document.write(' <div id="imgTitle_down"> <a class="trans"></a>');
//数字 按钮代 码 开始

for (var i = 1; i < imgUrl.length; ++i) {
document.write('<a id="link' + i + '" href="javascript:changeimg(' + i + ')" class="button" style="cursor:hand; " title="' + imgAlt[i] + '" onFocus="this.blur()">' + i + '</a>');
}
//数 字 按钮 代码 结 束
document.write('</div>');
document.write('</div>');
document.write('</div>');
document.write('</div>');
document.write('</div>');
}
//I E 结 束
</script>

<script language="javascript" type="text/javascript">
document.getElementsByName('imgInit').src = nextAd();
</script>
ChinaXtHuLang 2011-02-11
  • 打赏
  • 举报
回复
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
using System.Web.UI.HtmlControls;
using System.Configuration;
//导入类----------------------

using HuLangCms;

//----------------------
public partial class Demo : System.Web.UI.Page
{
public string strPageTitle;//页面标题
public string S_Pic;//幻灯片图片
public string S_Title;//幻灯片标题
public string S_Link;//幻灯片连接
ClassDB DB = new ClassDB();
protected void Page_Load(object sender, EventArgs e)
{
strPageTitle = "ASP.NET幻灯片";
}
/// <summary>
/// Flash幻灯片
/// </summary>
public string strFlash(string oNum)
{
string TopNum = " Top " + oNum + " ";
string strCode = "";
string oFlashPic = "";
string oFlashLink = "";
string oFlashTitle = "";
SqlConnection myConn = DB.GetConnection();
string strSql = "Select " + TopNum + " ID,PicName,PicLink,PicImg From Pic Order By Id Desc";
SqlCommand oIsCmd = new SqlCommand(strSql, myConn);
myConn.Open();
SqlDataReader sdr = oIsCmd.ExecuteReader();//查询,很明显可以看到 返回的是 SqlDataReader对象
if (sdr.Read())
{
strCode += "<script language=\"javascript\" type=\"text/javascript\">\r\n";
strCode += " var swf_width = 300;\r\n";
strCode += " var swf_height = 240;\r\n";
strCode += " var swf_path = '';\r\n";
strCode += " var files = '';\r\n";
strCode += " var texts = '';\r\n";
strCode += " var links = '';\r\n\r\n";
while (sdr.Read())//使用SqlDataReader的 sdr.Read()方法读出数据
{
oFlashPic += sdr["PicImg"].ToString() + "|";
oFlashLink += sdr["PicLink"].ToString() + "|";
oFlashTitle += sdr["PicName"].ToString() + "|";
S_Pic = oFlashPic.Substring(0, oFlashPic.LastIndexOf("|"));
S_Title = oFlashTitle.Substring(0, oFlashTitle.LastIndexOf("|"));
S_Link = oFlashLink.Substring(0, oFlashLink.LastIndexOf("|"));
}

strCode += " files += '" + S_Pic + "';\r\n";
strCode += " texts += '" + S_Title + "';\r\n";
strCode += " links += '" + S_Link + "';\r\n\r\n";

strCode += " document.write('<object classid=\"clsid:d27cdb6e-ae6d-11cf-96b8-444553540000\" codebase=\"http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0\" width=\"' + swf_width + '\" height=\"' + swf_height + '\">');\r\n";
strCode += " document.write('<param name=\"movie\" value=\"' + swf_path + 'bcastr31.swf\">');\r\n";
strCode += " document.write('<param name=\"quality\" value=\"high\">');\r\n";
strCode += " document.write('<param name=\"menu\" value=\"false\">');\r\n";
strCode += " document.write('<param name=\"wmode\" value=\"opaque\">');\r\n";
strCode += " document.write('<param name=\"FlashVars\" value=\"bcastr_file=' + files + '&bcastr_link=' + links + '&bcastr_title=' + texts + '&TitleBgColor=6699FF\">');\r\n";
strCode += " document.write('<embed src=\"' + swf_path + 'bcastr31.swf\" wmode=\"opaque\" FlashVars=\"bcastr_file=' + files + '&bcastr_link=' + links + '&bcastr_title=' + texts + '&TitleBgColor=6699FF&\" menu=\"false\" quality=\"high\" width=\"' + swf_width + '\" height=\"' + swf_height + '\" type=\"application/x-shockwave-flash\" pluginspage=\"http://www.macromedia.com/go/getflashplayer\" />');\r\n";
strCode += " document.write('</object>');\r\n";
strCode += "</script>\r\n";
}
else
{
strCode = "没有数据!";
}
sdr.Close();
myConn.Close();
return strCode;
}
}

.aspx页面调用:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Demo.aspx.cs" Inherits="Demo" %>
<!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><%=strPageTitle%></title>
</head>
<body>
<%=strFlash("5")%>
</body>
</html>

images/bcastr31.swf文件下载:http://www.newasp.net/images/bcastr31.swf

实在不知道咋搞。发你邮箱。我发你
xtxychc 2011-02-11
  • 打赏
  • 举报
回复
count = imgUrl.length - 1;
// var imgInit = document.getElementsByName('imgInit')
function playTran() {
if (document.all)
document.imgInit.filters.revealTrans.play();
}
var key = 0;
// var imgInit = document.getElementsByName('imgInit')
function nextAd() {
if (adNum < count)
adNum++;
else
adNum = 1;
if (document.all) {
document.imgInit.filters.revealTrans.Transition = 23;
document.imgInit.filters.revealTrans.apply();
playTran();
}
document.images.imgInit.src = imgUrl[adNum];
document.images.imgInit.alt = imgAlt[adNum];
document.getElementById('link' + adNum).style.background = buttonLineOn;
for (var i = 1; i <= count; ++i) {
if (i != adNum) {
document.getElementById('link' + i).style.background = buttonLineOff;
}
}
xtxychc 2011-02-11
  • 打赏
  • 举报
回复
 if (navigator.appName == "Netscape") {
document.write('<style type="text/css">');
document.write('.buttonDiv{height:4px;width:21px;}');
document.write('</style>');
function nextAd() {
if (adNum <= (imgUrl.length - 1))
adNum++;
else
adNum = 1;
theTimer = setTimeout("nextAd()", TimeOut);
document.images.imgInit.src = imgUrl[adNum];
document.images.imgInit.alt = imgAlt[adNum];
//document.getElementById('focustext').innerHTML=imgtext[adNum];//在图片下面显示图片的路径
//IE开始
子夜__ 2011-02-11
  • 打赏
  • 举报
回复
document.write('<div id="focuseFrom">');
document.write('</div>');

有开始 就要有结束啊。。

在检查下你的第5张图片路径。
xtxychc 2011-02-11
  • 打赏
  • 举报
回复
//焦 点 字 框 高 度 样 式 表 结束
imgUrls = "<%=imgUrl%>"; //获 取 后 台 c s 代 码 的属性
imgtexts = "<%=imgtext%>";
imgLinks = "<%=imgLink%>";
imgAlts = "<%=imgAlt%>";
imgUrl = imgUrls.split(",");
imgtext = imgtexts.split(",");
imgLink = imgLinks.split(",");
imgAlt = imgAlts.split(",");
function changeimg(n) {
adNum = n;
window.clearInterval(theTimer);
adNum = adNum - 1;
nextAd();
}
function goUrl() {
window.open(imgLink[adNum], '_blank');
}

//NetScape开始

62,074

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧