【问题标题】:Next and previous linking in JavaScript image gallery not workingJavaScript 图片库中的下一个和上一个链接不起作用
【发布时间】:2013-08-15 05:58:41
【问题描述】:

我需要在同一页面上有多个画廊(带有标题),并且一直在尝试实现这个 javascript,但我无法获得下一个 |以前为任一画廊工作的链接。 javascript 新手 - 有什么建议吗?

这里是小提琴:http://jsfiddle.net/astHh/11/

HTML:

<div style="text-align: center">
  <!--  Place the first image here  -->
  <img src="http://www.cool-smileys.com/images/out11.jpg" id="mypic" name="mypic" alt="information" border="0" height="150" width="200">
  <br>
  <!--  Place the text for the first image here  --><div id="burns">Caption one</div>
  <p>
  <a href="#" onclick="S2.UpDown(-1); return false;">&laquo; Previous</a> |
  <a href="#" onclick="S2.UpDown(1); return false;"> Next &raquo;</a>
</div>

<p>

<div style="text-align: center">
  <!--  Place the first image here  -->
  <img src="http://www.cool-smileys.com/images/out13.jpg" id="mypic2" name="mypic2" alt="information" border="0" height="150" width="200">
  <br>
  <!--  Place the text for the first image here  --> <div id="burns2">Caption two</div>
  <p>
  <a href="#" onclick="S2.UpDown(-1); return false;">&laquo; Previous</a> |
  <a href="#" onclick="S2.UpDown(1); return false;"> Next &raquo;</a>
</div>

Javascript:

<script type="text/javascript">


function SimpleSlideShow(o){
 this.img=document.getElementById(o.ImageID);
 this.txt=document.getElementById(o.TextID);
 this.ary=o.Array||[];
 this.cnt=0;
}

SimpleSlideShow.prototype.UpDown=function(ud){
  this.cnt+=ud;
  this.cnt=this.cnt<0?this.ary.length-1:this.cnt==this.ary.length?0:this.cnt;
  if (this.ary[this.cnt]){
   if (this.img&&this.ary[this.cnt][0]){
    this.img.src=this.ary[this.cnt][0];
    this.img.alt=this.ary[this.cnt][1];
   }
   if (this.txt){
    this.txt.innerHTML=this.ary[this.cnt][2]||'';
   }
  }
 }

S1=new SimpleSlideShow({
 ImageID:'mypic',
 TextID:'burns',
 Array:[
  ['http://www.cool-smileys.com/images/out11.jpg,' 'Caption one', 'The beautiful mountains'],
  ['http://www.cool-smileys.com/images/out10.jpg','Caption two','The crystal clear lake'],

]
});

S2=new SimpleSlideShow({
 ImageID:'mypic2',
 TextID:'burns2',
 Array:[
  ['http://www.cool-smileys.com/images/out13.jpg','caption one', 'The beautiful mountains'],
  ['http://www.cool-smileys.com/images/out12.jpg','caption two','The lonesome, barren tree']
]
});


</script>

【问题讨论】:

    标签: javascript navigation image-gallery


    【解决方案1】:

    您的 javascript 中有多个语法错误:

    从脚本窗格中删除:

    <script type="text/javascript">
    
    </script>
    

    在您对“S1”的定义中,您缺少一个逗号(就在“Caption one”之前):

    S1=new SimpleSlideShow({
        ImageID:'mypic',
        TextID:'burns',
        Array:[
            ['http://www.cool-smileys.com/images/out11.jpg,','Caption one', 'The beautiful mountains'],
            ['http://www.cool-smileys.com/images/out10.jpg','Caption two','The crystal clear lake'],
        ]
    });
    

    然后在 HTML 窗格中,您应该将第一组 prev/next 链接更新为目标 S1 而不是 S2。

    更新小提琴:http://jsfiddle.net/astHh/12/

    【讨论】:

    • 伙计,在我和你做同样的事情之前,真的应该看看它是否得到了回答。干得好!
    • 谢谢!这在小提琴中效果很好,当我将它放入dreamweaver并在safari/firefox中预览时它仍然不起作用。关于为什么的任何想法?我没有任何额外的 javascript。
    • 是否抛出任何错误?您是否将
    • 是的,我有
    • 如果我将
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-04-24
    • 2022-06-11
    • 2017-07-17
    • 2014-11-18
    • 1970-01-01
    • 1970-01-01
    • 2021-07-27
    相关资源
    最近更新 更多