发新贴  快速回复

关于js数组的问题,求大神前来看一下

ty97123
2014-12-16 08:49
<script type="text/javascript">
var arr=['yi','er','san'];
alert(arr.lenght);
</script>

这是代码,为什么弹不出arr的长度?显示undefind 不明确??

Sharp
长度不是length吗.拼错了?
2014-12-16 09:47  回复本帖
毛智美
 var arr=['yi','er','san'];
    alert(arr.length);     //长度单词写错了。
2014-12-16 11:42  回复本帖
ty97123
forum.php?mod=redirect&goto=findpost&pid=33837&ptid=10972
var arr=['yi','er','san'];
    alert(arr.length);     //长度单词写错了。

嗦嘎 这么低级的错误、 大哥呀还想问个问题啊
<script type="text/javascript">
window.err==function(){
    var oPrev=document.getElementById('prev');
    var oNext=document.getElementById('next');
    var oText=document.getElementById('text');
    var oSpan=document.getElementById('span1');
    var oImg=document.getElementById('img1');
    
    var arrUrl=['shangp2.jpg','shangp3.jpg'];
    var arrText=['第一件衣服','第二件衣服'];
    
    var num=0;
    
    oSpan.innerHTML=num+1+'/'+arrText.length;
    oImg.src=arrUrl[num];
    oText.innerHTML=arrText[num];
    
        oNext.err==function(){
        num++};
    };

</script>


问题是为什么点击oN ext图片没有切换到下一张?我把oNext的err=用alert测试了一下,点击oNext就能弹出来 ,

2014-12-16 14:02  回复本帖
ty97123
forum.php?mod=redirect&goto=findpost&pid=33837&ptid=10972
var arr=['yi','er','san'];
    alert(arr.length);     //长度单词写错了。

谢谢了 原来这么低级的错误
2014-12-16 14:03  回复本帖
毛智美
<!DOCTYPE html>
<html>
<head>
    <title></title>
    <meta charset="utf-8"/>
    <style type="text/css">
           ul{padding:0px;margin:0px;}
           li{list-style:none}
           #pic{width:400px;height:500px;position:relative;margin:0 auto;border:1px solid}
           #pic img{width:400px;height:500px;}
           #pic ul{width:40px;position:absolute;top:0px;right:-50px;}
           #pic li{width:40px;height:40px;margin-bottom: 4px;background:#666;}
           #pic .active{background:#FC3;}
           #pic span,#pic p{ width:400px;height:30px;line-height:30px;text-align:center;color: #222222;position:absolute;left:0}
           #pic span{top:0px}
           #pic p{bottom:0;margin:0px;}
    </style>
</head>
<body>

   <div id="pic"/>
       <img src=""/>
       <span></span>
       <p></p>
       <ul></ul>
   </div>
</body>
<script type="text/javascript">

    var  oPic=document.getElementById("pic");
    var  oImg=document.getElementsByTagName("img")[0];
    var  oSpan=document.getElementsByTagName("span")[0];
    var  oP=document.getElementsByTagName("p")[0];
    var  oUl=document.getElementsByTagName("ul")[0];
    var  aLi=oUl.getElementsByTagName("li");

    var arr = ['1.png','2.png','3.png'];
    var text = ['one','two','three'];
    var num=0;
    var oldLi=null;
    for(var i=0;i<arr.length;i++){

        oUl.innerHTML+= "<li></li>"
    }

    // 初始化
    oldLi=aLi[num];    //  给思路二做初始化
    oP.innerHTML = text[num];
    oSpan.innerHTML = num+1+"/"+arr.length;
    oImg.src=arr[num];
    aLi[num].className="active";


    for(var i=0;i<aLi.length;i++){

         aLi[i].num = i;
         aLi[i].err= = function(){

               oImg.src = arr[this.num];    // this.num 是自定义的,i循环过来的值赋值给num , 身上的数字扔到 数组 里面,建立匹配对应关系。
               oP.innerHTML = text[this.num];
               oSpan.innerHTML = 1+this.num+"/"+arr.length;

               // 思路一: 全部清除 ,当前添加

               for(var i=0;i<aLi.length;i++){

                     aLi[i].className= "";

                     this.className="active";
               }


              // 思路二: 清空上个 ,当前添加

             /*  oldLi.className="";
               oldLi=this
               this.className="active";*/

         }
    }
</script>
</html>
2014-12-16 14:08  回复本帖
毛智美
不好意思,那个发错了。这个。 
<!DOCTYPE html>
<html>
<head>
    <title></title>
    <meta charset="utf-8"/>
    <style type="text/css">

        #content{

             height:400px;
             width:400px;
             border:10px solid;
            margin:0 auto;
            position:relative;
            background-color:#f1f1f1;
        }
        #content a{

              width:40px;
              height:40px;
              border:2px solid #ffffff;
              background-color:#000000;
              line-height:40px;
              text-align:center;
              text-decoration:none;
              color:#fff;
              font-weight:bold;
              font-size:24px;
              position:absolute;
              top:175px;
              opacity:0.7;

        }
        #content a:hover{

            opacity:1;
        }
        #prev{

            left:10px;
        }
        #next{

            right:10px;
        }
        #text,#span1{
            height:30px;
            line-height:30px;
            width:400px;
            color:#fff;
            text-align:center;
            background-color:#222222;
            position:absolute;
            opacity:0.7;
            left:0px;
        }
        #text{
            bottom:0px;
            margin:0px;
        }
        #span1{
            top:0px;
            margin:0px;
        }
        img{
            width:400px;
            height:400px;
        }
    </style>
</head>
<body>
      <div id="content">
          <a id="prev" href="javascript:;"><</a>
          <a id="next" href="javascript:;">></a>
          <p id="text">文字正在计算中..</p>
          <span id="span1">数字正在计算中...</span>
          <img  id="Img"/>
      </div>
      <script type="text/javascript">
            var  content=document.getElementById("content");
            var  prev=document.getElementById("prev");
            var  next=document.getElementById("next");
            var  text=document.getElementById("text");
            var  span1=document.getElementById("span1");
            var  Img=document.getElementById("Img");
            var  num=0;
            var ImgArr=['1.png','2.png','3.png'];
            var  textArr=['one','two','three'];

            function ftTab(){

              /*  Img.src=ImgArr[num];*/
                Img.src=ImgArr[num];
                text.innerHTML=textArr[num];
                span1.innerHTML=num+1+"/"+ImgArr.length

            }
            ftTab();    /*这里如果不调用,初始的第一张不会显示出来*/
            next.err==function(){
                num++;
                if(num == ImgArr.length){
                   num=0;
                }
                ftTab();
            }
            prev.err==function(){
                num--;
                if(num ==-1){
                    num=ImgArr.length-1;
                }
                ftTab();
            }



      </script>
</body>
</html>

2014-12-16 14:13  回复本帖
毛智美
点击对谁进行num++  ,  
      oSpan.innerHTML=num+1+'/'+arrText.length;
        oImg.src=arrUrl[num];
        oText.innerHTML=arrText[num];

需要把这个放进去。

2014-12-16 14:17  回复本帖
ty97123
forum.php?mod=redirect&goto=findpost&pid=33851&ptid=10972
点击对谁进行num++  ,  
      oSpan.innerHTML=num+1+'/'+arrText.length;
        oImg.src=arrUrl[num] ...

太感谢你了{:soso_e105:}
2014-12-16 14:43  回复本帖
 
月亮下的鱼

ty97123 2014-12-16 14:43发表的内容:

forum.php?mod=redirect&goto=findpost&pid=33851&ptid=10972
点击对谁进行num++  ,  
      oSpan.innerHTML=num+1+'/'+arrText.length;
        oImg.src=arrUrl[num] ...

太感谢你了{:soso_e105:}
2333333
2018-02-05 20:38  回复本帖
登录 后才可以发表回复