2012-08-13 2 views
0

머리 부분의 맨 위에있는 자바 스크립트입니다.HTML URL에 배열 사용

<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> 

그러나 변수는 문자열로 대체되지 않습니다

그래서 나는 시도?

+0

가;. html로 이미 전에 렌더링 – PitaJ

+0

'는 할 수있다 javascript로 무엇이든 할 수 있습니다. 따라서 HTML에 문자열을 추가하는 것입니다. – PeeHaa

+2

음, 자습서를 검색하여 javascript와 html이 어떻게 상호 작용 하는지를 배울 수 있습니다. 이것은 PHP와 같은 서버 측 언어가 아니기 때문에 수행하려는 방식대로 수행 할 수 없습니다. – TheZ

답변

2

당신은 ('myGallery [0]) HREF = myGallery [0]`document.getElementById를 할 필요가 방법에 대한 <a href="" onclick="location.href=myGallery[0];return false;">image</a>

1

당신은

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

같은 값을 얻을 그리고 링크에서 함수를 호출하는 함수를 만들 수 있습니다.

onclick = "loadPic(0)"