在 HTML URL 中使用数组

Use Array in HTML URL

本文关键字:数组 HTML URL      更新时间:2023-09-26

这是我在头部顶部的Javascript。

<script type="text/javascript" charset="utf-8">
    var myGallery=new Array();
            myGallery[0]="../images/gallery2/2009_09_04-BretErnst_0013.jpg"; 
</script>

现在我希望能够调用 myGallery[0] 并将其用作 href。

所以我尝试:

<li>
    <a href="myGallery[0]" rel="prettyPhoto[gallery1]" title="You can add caption to pictures. You can add caption to pictures. You can add caption to pictures.">
        <img src="myGallery[0]" width="60" height="60" alt="Red round shape" />
    </a>
</li>

但是变量没有被字符串替换...

帮助?

<a href="" onclick="location.href=myGallery[0];return false;">image</a>怎么样

你可以创建一个函数来获取这样的值

function loadPic(index){
  window.location = myGallery[index];
}

并从链接调用该函数。

onclick = "loadPic(0)"