我在网上找了一段实现幻灯片效果的javascript代码,但是我想实现,读取数据库中数据表里的前5张图片显示出来,请问怎么修改这段代码,请大伙指教一下了(就是把标红的那一段改成从数据表里读取图片)数据表pic
ID Picpath
1 /image/1.gif
2 /image/2.gif
3 /image/3.gif
4 /image/4.gif
5 /image/5.gif
6 /image/6.gif
.......
<META http-equiv="Content-Type" content="text/html; charset=gb2312">
<style type="text/css"> <!-- select {}{ font-family: "tahoma"; font-size: 10px; color: #666666}
input {}{ font-family: "tahoma"; font-size: 10px; color: #000000; border: #666666; border-style: solid; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px}
--></style>
<SCRIPT LANGUAGE="JavaScript">var rotate_delay = 1300; // delay in milliseconds (5000 = 5 secs)
current = 0;
function next() {
if (document.slideform.slide[current+1]) {
document.images.show.src = document.slideform.slide[current+1].value;
document.slideform.slide.selectedIndex = ++current;
}
else first();
}
function previous() {
if (current-1 >= 0) {
document.images.show.src = document.slideform.slide[current-1].value;
document.slideform.slide.selectedIndex = --current;
}
else last();
}
function first() {
current = 0;
document.images.show.src = document.slideform.slide[0].value;
document.slideform.slide.selectedIndex = 0;
}
function last() {
current = document.slideform.slide.length-1;
document.images.show.src = document.slideform.slide[current].value;
document.slideform.slide.selectedIndex = current;
}
function ap(text) {
document.slideform.slidebutton.value = (text == "暂停") ? "开始" : "暂停";
rotate();
}
function change() {
current = document.slideform.slide.selectedIndex;
document.images.show.src = document.slideform.slide[current].value;
}
function rotate() {
if (document.slideform.slidebutton.value == "暂停") {
current = (current == document.slideform.slide.length-1) ? 0 : current+1;
document.images.show.src = document.slideform.slide[current].value;
document.slideform.slide.selectedIndex = current;
window.setTimeout("rotate()", rotate_delay);
}
}</SCRIPT>
<body bgcolor="#ffffff" text="#000000">
<form name="slideform">
<table cellspacing="1" cellpadding="4" bgcolor="#000000">
<tr>
<td align="center" bgcolor="white" width="500" height="300">
<img src="1.gif" name="show">
</td>
</tr>
<tr>
<td align="center" bgcolor="#c0c0c0">
<select name="slide" onChange="change();">
<option value="1.gif" selected>
1
<option value="2.gif">
2
<option value="3.gif">
3
<option value="4.gif">
4
</option>
</select> </td>
</tr>
<tr>
<td align="center" bgcolor="#c0c0c0">
<input type="button" onClick="first();" value="|<<" title="Beginning"> <input type="button" onClick="previous();" value="<<" title="Previous">
<input type="button" name="slidebutton" onClick="ap(this.value);" value="开始" title="AutoPlay">
<input type="button" onClick="next();" value=">>" title="Next"> <input type="button" onClick="last();" value=">>|" title="End">
</td>
</tr>
</table>
</form>
</body>
ID Picpath
1 /image/1.gif
2 /image/2.gif
3 /image/3.gif
4 /image/4.gif
5 /image/5.gif
6 /image/6.gif
.......
<META http-equiv="Content-Type" content="text/html; charset=gb2312">
<style type="text/css"> <!-- select {}{ font-family: "tahoma"; font-size: 10px; color: #666666}
input {}{ font-family: "tahoma"; font-size: 10px; color: #000000; border: #666666; border-style: solid; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px}
--></style>
<SCRIPT LANGUAGE="JavaScript">var rotate_delay = 1300; // delay in milliseconds (5000 = 5 secs)
current = 0;
function next() {
if (document.slideform.slide[current+1]) {
document.images.show.src = document.slideform.slide[current+1].value;
document.slideform.slide.selectedIndex = ++current;
}
else first();
}
function previous() {
if (current-1 >= 0) {
document.images.show.src = document.slideform.slide[current-1].value;
document.slideform.slide.selectedIndex = --current;
}
else last();
}
function first() {
current = 0;
document.images.show.src = document.slideform.slide[0].value;
document.slideform.slide.selectedIndex = 0;
}
function last() {
current = document.slideform.slide.length-1;
document.images.show.src = document.slideform.slide[current].value;
document.slideform.slide.selectedIndex = current;
}
function ap(text) {
document.slideform.slidebutton.value = (text == "暂停") ? "开始" : "暂停";
rotate();
}
function change() {
current = document.slideform.slide.selectedIndex;
document.images.show.src = document.slideform.slide[current].value;
}
function rotate() {
if (document.slideform.slidebutton.value == "暂停") {
current = (current == document.slideform.slide.length-1) ? 0 : current+1;
document.images.show.src = document.slideform.slide[current].value;
document.slideform.slide.selectedIndex = current;
window.setTimeout("rotate()", rotate_delay);
}
}</SCRIPT>
<body bgcolor="#ffffff" text="#000000">
<form name="slideform">
<table cellspacing="1" cellpadding="4" bgcolor="#000000">
<tr>
<td align="center" bgcolor="white" width="500" height="300">
<img src="1.gif" name="show">
</td>
</tr>
<tr>
<td align="center" bgcolor="#c0c0c0">
<select name="slide" onChange="change();">
<option value="1.gif" selected>
1
<option value="2.gif">
2
<option value="3.gif">
3
<option value="4.gif">
4
</option>
</select> </td>
</tr>
<tr>
<td align="center" bgcolor="#c0c0c0">
<input type="button" onClick="first();" value="|<<" title="Beginning"> <input type="button" onClick="previous();" value="<<" title="Previous">
<input type="button" name="slidebutton" onClick="ap(this.value);" value="开始" title="AutoPlay">
<input type="button" onClick="next();" value=">>" title="Next"> <input type="button" onClick="last();" value=">>|" title="End">
</td>
</tr>
</table>
</form>
</body>
<?php
$con = mysql_connect('localhost', 'root', 'root'); //连接DB
mysql_select_db("test", $con);//选择数据库
$sql="SELECT * FROM pic";
$result = mysql_query($sql);
echo " <select name=\"slide\" onChange=\"change();\"> ";
while($row = mysql_fetch_array($result)){
echo "<option value=\"" . $row['Picpath'] . "\">".$row['ID'] ."</option>";
}
echo " </select> ";
mysql_close($con);
?>
<option ></option>
</select>后台CS代码里面:using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;using System.Web.UI.HtmlControls;
using System.Text;using System.Data.OracleClient;namespace ReadPic
{
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
OracleConnection conn = new OracleConnection(); //如果使用sqlserver 换一下代码
conn.ConnectionString = "Data Source=WV;Persist Security Info=True;User ID=WV;Password=WV;Unicode=True"; conn.Open(); //打开连接
OracleCommand cmd = new OracleCommand("select id,Picpath from pic", conn);
OracleDataReader dr = cmd.ExecuteReader();
HtmlSelect select = (HtmlSelect)FindControl("slide"); //查找到前台的下拉框
StringBuilder options = new StringBuilder();
while (dr.Read())
{
ListItem o = new ListItem(dr.GetInt32(0).ToString(), dr.GetString(1)); //创建option选项
select.Items.Add(o); //添加到下拉框里面
}
conn.Close();
}
}
}