我把页面代码贴出来:myimg-1.1.js 代码:var MyImg = {

img : [],
imglink : [],
imgalt : [],

num : -1,
time : 5000,

$ : function(id) {
return document.getElementById(id);
},
init : function(img, imglink, imgalt, time) {
this.img = img;
this.imglink = imglink;
this.imgalt = imgalt;
if(time && time != 0 && time != '0') this.time = time;
},
show : function(idx) {
if(document.all) {
myimgRotator.filters.revealTrans.Transition = Math.floor(Math.random() * 20);
myimgRotator.filters.revealTrans.apply();
}
document.images.myimgRotator.src = this.img[idx];
document.images.myimgRotator.alt = this.imgalt[idx];
if(document.all) myimgRotator.filters.revealTrans.play();
for(var i=0;i<this.img.length;i++) {
var o = this.$('myimg_a_' + i);
if(i == idx) {
o.style.backgroundColor = 'red';
o.innerHTML = '&nbsp;<font color=#ffffff>' + (i+1) + '</font>&nbsp;';
} else {
o.style.backgroundColor = '';
o.innerHTML = '&nbsp;' + (i+1) + '&nbsp;';
}
}
this.$('myimgalt').innerHTML = '&nbsp;<a href="javascript:MyImg.linkURL();" style="text-decoration:none;color:blue;">' + (this.imgalt && this.imgalt[idx] ? this.imgalt[idx] : '') + '</a>';
},
next : function() {
this.num++;
if(this.num >= this.img.length) this.num = 0;
this.show(this.num);
setTimeout("MyImg.next()", this.time);
},
slct : function(idx) {
this.num = idx - 1;
var tmp = this.time;
this.time = 1000000;
this.show(idx);
this.time = tmp;
},
linkURL : function() {
var url = (this.imglink && this.imglink[this.num]) ? this.imglink[this.num] : this.img[this.num];
window.open(url);
},
getHTML : function(img, imglink, imgalt, w, h, time) {
this.init(img, imglink, imgalt, time);
w = (w) ? w : 400;
h = (h) ? h : 300;
var aa = '';
for(var i=0;i<this.img.length;i++) {
aa += '<a id=myimg_a_' + i + ' onclick="MyImg.slct(' + i + ');" style="color:#000;cursor:pointer;" title="' + this.imgalt[i] + '">&nbsp;' + (i+1) + '&nbsp;</a>';
}
return '<table boder=0 width=' + w + ' height=' + h + '><tr><td><a href="javascript:MyImg.linkURL();"><img style="FILTER:revealTrans(duration=2,transition=20,border:1px solid #000000" src="' + this.img[0] + '" width=' + w + ' height=' + h + ' border=0 name="myimgRotator" alt=""></a><div style="font-size:13px;margin-top:-30px;"><table border=0 width=' + w + ' bgcolor="#FFFFFF" style="filter:alpha(opacity=80);opacity:0.8;"><tr><td width=50%><div id=myimgalt></div></td><td width=50% align=right>' + aa + '</td></tr></table></div></td></tr></table>';
},

// ************** 通用调用函数 ******************
disp : function(img, imglink, imgalt, w, h, time, id) {
var html = this.getHTML(img, imglink, imgalt, w, h, time);
if(id) this.$(id).innerHTML = html;
else document.write(html);
this.next();
}
};
 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 type="text/javascript">
    var img = [
    "imgs/5.jpg",
    "imgs/2.jpg",
    "imgs/3.jpg",
    "imgs/4.jpg",
    "imgs/1.jpg",
    "imgs/6.jpg",
    "imgs/7.jpg",
    "imgs/8.jpg"
    ];
    var imglink = [
    "http://www.baidu.com",
    "http://www.yahoo.com.cn",
    "http://www.QQ.com",
    "http://www.sina.com",
    "http://www.xiaji.com",
    "http://www.baidu.com",
    "http://www.g-g.com",
    "http://www.xiaji.com"
    ];
    var imgalt = [
    "百度",
    "雅虎",
    "QQ",
    "新浪",
    "中国人民",
    "四川",
    "这是大哥",
    "嘿嘿 "
    ];
    </script></head>
<body>
    <form id="form1" runat="server">
    <div>    
    <script type="text/javascript" src="myimg-1.1.js"></script>        <script type="text/javascript">MyImg.disp(img, imglink, imgalt, 400, 300, 5000);</script>    </div>
    </form>
</body>
</html>这代码放到HTML页面运行就一切正常,或者把这里的   <form id="form1" runat="server">这个表单去掉也可以运行,不明白为什么,form表单去掉了其他内容就不晓得改咋写了呢。请高手解答。

解决方案 »

  1.   

    runat="server"不是服务器端的控件么
      

  2.   


    <%@ Page Language="C#" AutoEventWireup="true" CodeFile="test.aspx.cs" Inherits="Tools_test" %><!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 type="text/javascript">
            var MyImg = {            img: [],
                imglink: [],
                imgalt: [],            num: -1,
                time: 5000,            $: function(id) {
                    return document.getElementById(id);
                },
                init: function(img, imglink, imgalt, time) {
                    this.img = img;
                    this.imglink = imglink;
                    this.imgalt = imgalt;
                    if (time && time != 0 && time != '0') this.time = time;
                },
                show: function(idx) {
                    //使用document.getElementById方法获取img元素对象
                    var myimgRotator = document.getElementById("myimgRotator");
                    if (document.all) {//最好不要这样判断浏览器的类型
                        myimgRotator.filters.revealTrans.Transition = Math.floor(Math.random() * 20);
                        myimgRotator.filters.revealTrans.apply();
                    }
                    document.images.myimgRotator.src = this.img[idx];
                    document.images.myimgRotator.alt = this.imgalt[idx];
                    if (document.all) myimgRotator.filters.revealTrans.play();
                    for (var i = 0; i < this.img.length; i++) {
                        var o = this.$('myimg_a_' + i);
                        if (i == idx) {
                            o.style.backgroundColor = 'red';
                            o.innerHTML = '&nbsp;<font color=#ffffff>' + (i + 1) + '</font>&nbsp;';
                        } else {
                            o.style.backgroundColor = '';
                            o.innerHTML = '&nbsp;' + (i + 1) + '&nbsp;';
                        }
                    }
                    this.$('myimgalt').innerHTML = '&nbsp;<a href="javascript:MyImg.linkURL();" style="text-decoration:none;color:blue;">' + (this.imgalt && this.imgalt[idx] ? this.imgalt[idx] : '') + '</a>';
                },
                next: function() {
                    this.num++;
                    if (this.num >= this.img.length) this.num = 0;
                    this.show(this.num);
                    setTimeout("MyImg.next()", this.time);
                },
                slct: function(idx) {
                    this.num = idx - 1;
                    var tmp = this.time;
                    this.time = 1000000;
                    this.show(idx);
                    this.time = tmp;
                },
                linkURL: function() {
                    var url = (this.imglink && this.imglink[this.num]) ? this.imglink[this.num] : this.img[this.num];
                    window.open(url);
                },
                getHTML: function(img, imglink, imgalt, w, h, time) {
                    this.init(img, imglink, imgalt, time);
                    w = (w) ? w : 400;
                    h = (h) ? h : 300;
                    var aa = '';
                    for (var i = 0; i < this.img.length; i++) {
                        aa += '<a id=myimg_a_' + i + ' onclick="MyImg.slct(' + i + ');" style="color:#000;cursor:pointer;" title="' + this.imgalt[i] + '">&nbsp;' + (i + 1) + '&nbsp;</a>';
                    }
                    //将img元素的name属性修改为id
                    return '<table boder=0 width=' + w + ' height=' + h + '><tr><td><a href="javascript:MyImg.linkURL();"><img style="FILTER:revealTrans(duration=2,transition=20,border:1px solid #000000" src="' + this.img[0] + '" width=' + w + ' height=' + h + ' border=0 id="myimgRotator" alt=""></a><div style="font-size:13px;margin-top:-30px;"><table border=0 width=' + w + ' bgcolor="#FFFFFF" style="filter:alpha(opacity=80);opacity:0.8;"><tr><td width=50%><div id=myimgalt></div></td><td width=50% align=right>' + aa + '</td></tr></table></div></td></tr></table>';
                },            // ************** 通用调用函数 ******************
                disp: function(img, imglink, imgalt, w, h, time, id) {
                    var html = this.getHTML(img, imglink, imgalt, w, h, time);
                    if (id) this.$(id).innerHTML = html;
                    else document.write(html);
                    this.next();
                }
            };        var img = [
          "imgs/5.jpg",
          "imgs/2.jpg",
          "imgs/3.jpg",
          "imgs/4.jpg",
          "imgs/1.jpg",
          "imgs/6.jpg",
          "imgs/7.jpg",
          "imgs/8.jpg"
          ];
            var imglink = [
          "http://www.baidu.com",
          "http://www.yahoo.com.cn",
          "http://www.QQ.com",
          "http://www.sina.com",
          "http://www.xiaji.com",
          "http://www.baidu.com",
          "http://www.g-g.com",
          "http://www.xiaji.com"
          ];
            var imgalt = [
          "百度",
          "雅虎",
          "QQ",
          "新浪",
          "中国人民",
          "四川",
          "这是大哥",
          "嘿嘿 "
          ];
        </script></head>
    <body>
        <form id="form1" runat="server">
        <div>        <script type="text/javascript">            MyImg.disp(img, imglink, imgalt, 400, 300, 5000);</script>    </div>
        </form>
    </body>
    </html>