我把页面代码贴出来: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 = ' <font color=#ffffff>' + (i+1) + '</font> ';
} else {
o.style.backgroundColor = '';
o.innerHTML = ' ' + (i+1) + ' ';
}
}
this.$('myimgalt').innerHTML = ' <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] + '"> ' + (i+1) + ' </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表单去掉了其他内容就不晓得改咋写了呢。请高手解答。
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 = ' <font color=#ffffff>' + (i+1) + '</font> ';
} else {
o.style.backgroundColor = '';
o.innerHTML = ' ' + (i+1) + ' ';
}
}
this.$('myimgalt').innerHTML = ' <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] + '"> ' + (i+1) + ' </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表单去掉了其他内容就不晓得改咋写了呢。请高手解答。
解决方案 »
- 大家帮忙看下这段代码,不清楚哪的问题...
- 这段代码加密了?
- 急,Error:'window.button1.style' 为空或不是对象,如何将代码写规范,帮忙改改不会javascript
- 动态生成select option 的问题,做了一下午,明天要交,但实在是没有办法了,那位帮帮谢谢了
- [求助]编辑器中的“插入链接“怎么写
- 请教这样正则表达式如何写
- 前台解析数据出现排序错误
- 如何在见面中实现大图片的鼠标拖动
- 弹出的子窗口怎样得到父窗口中多选框选中的值,并和子窗口的表单一起发送
- 關于如何在網頁下載完畢後如何立刻將表單內的控件disabled掉,及可否在用javascrip有沒有提供一個調用browser更新的方法,謝高手
- 省市二级联动菜单
- 正则表达式 求助
<%@ 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 = ' <font color=#ffffff>' + (i + 1) + '</font> ';
} else {
o.style.backgroundColor = '';
o.innerHTML = ' ' + (i + 1) + ' ';
}
}
this.$('myimgalt').innerHTML = ' <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] + '"> ' + (i + 1) + ' </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>