Linux中国 Linux中国门户站!
设为主页 设为主页
收藏本站 收藏本站
 
当前位置 :首页 ->网站设计 ->JavaScript ->正文

利用javascript从数据库取数据来实现CSDN首页图片的切换效果

来源:Linuxdby.com 作者:Webmaster 时间:2007-06-05 点击: [收藏] [投稿]

 } else {

  break;

 }

}

function playTran(){

 if (document.all)

  imgInit.filters.revealTrans.play(); 

}

var key=0;

function nextAd(){

 if(adNum<count)adNum++ ;

 else adNum=1;

 

 if( key==0 ){

  key=1;

 } else if (document.all){

  imgInit.filters.revealTrans.Transition=23;

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

 }

    //focustext.innerHTML=imgtext[adNum];//在图片下面显示路径

 theTimer=setTimeout("nextAd()", TimeOut);

}

document.write('<a target=_self href="javascript:goUrl()"><img style="FILTER: revealTrans(duration=1,transition=5);" src="javascript:nextAd()" 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>');

}

//IE结束

 

</script>

里面重要的地方都有注释了,直接复制到你的aspx代码中即可。

注意:在<body></body>中不要<form></form>标签,直接在<div align=left>

</div>中输入上面的js代码即可。不知道为什么有form总是报imgInit错误。

4.在cs进行数据库调用:直接代码了,呵呵呵不会看不懂吧

protected void Page_Load(object sender, EventArgs e)

    {

        if (!Page.IsPostBack)

        {

            bind();

        }

    }

    public string imgUrl = "", imgLink = "", imgtext = "", imgAlt = "";

    void bind()

    {

        using (SqlConnection connection = new SqlConnection("server=.;database=northwind;uid=sa;pwd=123"))

        {

            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() + ",";

            }

        }

 

    }

 

测试环境:vs2005

如果看着不错对你有用麻烦顶一下啊!如果有好的建议或者好的解决方案也麻烦你共享一下,谢谢!

E-mail:teng_s2000@126.com

QQ:37210956

 如果您对本文有任何疑问或者建议,请到讨论区发表您的意见: >> 论坛入口 <<



上一篇:将js文件编译成动态链接库(dll)文件   下一篇:Javascript模拟的DOS窗口

文章评论】 【收藏本文】 【推荐好友】 【打印本文】 【我要投稿】 【论坛讨论
更多相关文章
Power by linux-cn.com 粤ICP备05006655号