主要概要如下:
以下javascript代码在普通html文件中调试没问题,但将代码拷贝到Visual Studiou 2005中的文件(aspx文件和html文件)中去时调试就报错"提示缺少对象",请问是何故?该javascript是做图片轮播的,当然如果你有图片轮播并在Visual Studiou 中调试没问题的话也可发给我嘛,谢谢[email protected]
代码如下(调试没问题,但把代码拷贝到Visual Studio 中的文件中去后就会出问题):
1.html文件的代码如下 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitionl/EN">
<html xmlns="http://www.w3c.org/1999/xhtmls">
<head>
<title></title>
<script src="cycle_image.js" type="text/javascript" language="javascript"></script>
</head> <body>
<script>
//芞繚噤
var image= new Array("1.jpg","2.jpg","3.jpg","4.jpg");
//蟈諉華硊
var link= new Array("http://localhost/z_study/123/1.jpg","http://localhost/z_study/123/2.jpg","http://localhost/z_study/123/3.jpg","http://www.baidu.com");
//鏡扴恅趼
var description= new Array("1.jpg:   SEXY    ~~~~","2.jpg :  HOT GIRL!!!","3.jpg :  SEXY GIRL!!!","zhanwumiaoshu");displaye(3,300,500,image,description,link,"_blank"); </script>
</body>
</html>
2.cycle_image.js代码如下
var showed=0;
var selected=0;
var arr_length=0;
var num_bottom="50";
var num_right="5";
var num_height="30";
var num_font_size="12"; 
var num_color="#ffffff";
var num_background_color="#00ccff";
var num_background_highlight="#ccffaa";
var des_bottom="25";
var des_left="5";
var des_color="#ff0000";
var des_font_weight="bold";
var des_font_style="normal";
var des_background_color="#ffffff";
var des_opacity="0.5";
var des_filter="50";function displaye(cycle,height,width,image,description,link,target)
{
arr_length=image.length;
r_cycle=cycle;
document.write("<div id=\"cycle_image\" style=\"width:"+width+"px; height:"+height+"px; position:relative;\">");
if(undefined==target){
target="_blank";
}
for(var i=0;i<image.length;i++){
document.write("<div id=\"img"+i+"\" style=\"filter:alpha(opacity=0);opacity:0;overflow:hidden; width:"+width+"px;height:"+height+"px; top:0px;left:0px;position:absolute;\">");
document.write("<a href=\""+link[i]+"\" target=\""+target[i]+"\">");
document.write("<img src=\""+image[i]+"\" id=\"img"+length+" alt=\""+description+"\" border=0 />");
document.write("</a>");
document.write("</div>");
}
document.write("<div id=\"num\" style=\"height:"+num_height+"px; top:"+(height-num_bottom)+"px;right:"+num_right+"px; position:absolute;\">");
for(var i=0;i<image.length;i++){
document.write("<span id=\""+i+"\" style=\"font-size:"+num_font_size+"px; border:1px "+num_color+" solid ;cursor:pointer;background-color:"+num_background_color+";color:"+num_color+";display:block;float:left;margin-bottom:2px;padding:1px 5px;margin-left:1px;\" onclick=\"mClick(this)\" onMouseOver=\"mOver(this);\" onMouseOut=\"mOut(this);\">");
document.write(i+1);
document.write("</span> ");
}
document.write("</div>");
for(var i=0;i<image.length;i++){
if(""!=description[i]){
document.write("<div id=\"description"+i+"\" style=\"filter:alpha(opacity=0);opacity:0;background-color:"+des_background_color+";top:"+(height-des_bottom)+"px;left:"+des_left+"px; position:absolute;\">");
document.write("<a href=\""+link[i]+"\" target=\""+target+"\" style=\"font-style:"+des_font_style+";font-weight :"+des_font_weight+";color:"+des_color+"; text-decoration:none;\">");
document.write(description[i]);
document.write("</a>");
document.write("</div>");
}
}
document.write("</div>");
document.getElementById("img"+showed).style.filter="alpha(opacity=100)";
document.getElementById("img"+showed).style.opacity=1;
document.getElementById("description"+showed).style.opacity=des_opacity;
document.getElementById("description"+showed).style.filter="alpha(opacity="+des_filter+")";
document.getElementById(showed).style.color=num_background_color;
document.getElementById(showed).style.background=num_color;
document.getElementById(showed).style.border="1px "+num_background_color+" solid";
setInterval("timeout()",r_cycle*1000);
}function mOver(object){
if(showed!=object.id){
object.style.background=num_background_highlight;
}
}
function mOut(object){
if(showed!=object.id){
object.style.background=num_background_color;
object.style.color=num_color;
}
}function mClick(object){
selected=object.id;
if(showed!=selected){
document.getElementById(showed).style.border="1px "+num_color+" solid";
document.getElementById(showed).style.background=num_background_color;
document.getElementById(showed).style.color=num_color;
document.getElementById("img"+showed).style.opacity=0;
document.getElementById("img"+showed).style.filter="alpha(opacity=0)";
document.getElementById("description"+showed).style.opacity=0;
document.getElementById("description"+showed).style.filter="alpha(opacity=0)"; document.getElementById("img"+selected).style.opacity=1;
document.getElementById("img"+selected).style.filter="alpha(opacity=100)";
document.getElementById("description"+selected).style.filter="alpha(opacity="+des_filter+")";
document.getElementById("description"+selected).style.opacity=des_opacity;
document.getElementById(selected).style.background=num_color;
document.getElementById(selected).style.color=num_background_color;
document.getElementById(selected).style.border="1px "+num_background_color+" solid"; showed=selected;
}
}function timeout(){
if(selected<arr_length-1){
selected++;
mClick(document.getElementById(selected));
}else{
selected=0;
mClick(document.getElementById(selected));
}
}

解决方案 »

  1.   

    建议你用JQuery  参考
      

  2.   

    我对用大段document.write来生成HTML代码的行为极度不能忍受。Use DOM Please!!
      

  3.   

    编码都乱了,建议楼主把编码统一,有的时候编码不统一JS可能不能运行,
    你看看你的WEB.CONFIG里面的 PAGE设计,是用什么编码,编码统一了应该是可以运行的!
      

  4.   

    看看ASPX生成的源码是什么样的?另外,最好把脚本放在网页尾部,不要放在前面
      

  5.   

    我这边帮你看了下! 没有问题!你是在什么浏览器下看的呢?我在IE7下 
       我在给你发几个别的效果的!你可以注意查收!我的Mail是[email protected]
      

  6.   

    cycle_image.js
    和你的html页 ,打开文件,在vs中 高级保存选项,编码UTF-8 with sighture, js文件也要保存一次,和html一样。试试看,不行的话都存存在gb2312在试一次,html和js页编码要保持一致
      

  7.   

    <script src="cycle_image.js" type="text/javascript" language="javascript" charset="gb2312"> </script> 
    如果js是gb2312的话.
      

  8.   

    可能是你的对象Name没有找到。。