2016-06-09 135 views
-4

我有3張圖片但不在線,我需要將這三張圖片鏈接到不同的頁面上! 每幅圖像各個環節Javascript link in image

var images = [ 
 
    'image/dragao1.jpg', 
 
    'image/dragao2.jpg', 
 
    'image/dragao3.jpg' 
 
]; 
 

 
function slideShowForward() { 
 
    images.push(images.shift()); 
 
    document.getElementById('imagesP').style.backgroundImage = 'url(' + images[0] + ')'; 
 
} 
 

 
function slideShowBack() { 
 
    images.unshift(images.pop()); 
 
    document.getElementById('imagesP').style.backgroundImage = 'url(' + images[0] + ')'; 
 
}
<div id="imagesP" style=" border: 1px solid black; height: 200px; width:750px;"> 
 
    <div id="form"> 
 
    <input type="button" value="previous" onclick="slideShowBack();" style="width: 39px; height: 34px;" /> 
 
    <input type="button" value="next" onclick="slideShowForward();" style="width: 39px; height: 34px;" /> 
 
    </div> 
 
</div>

+0

請編輯您的問題,編輯代碼段並將您的HTML _there_,**放入評論**中。仍然沒有提及任何地方的鏈接。你是什​​麼意思_「我必須把圖像鏈接」_? – Xufox

+0

你需要添加一個onclick到div如果你想點擊圖片去某個地方 – mplungjan

回答

0

var images = [ 
 
    'http://cinemacomrapadura.com.br/imagens/2014/01/20140127-como-treinar-seu-dragao1.jpg', 
 
    'http://cinemacomrapadura.com.br/imagens/2014/01/20140127-como-treinar-seu-dragao2.jpg', 
 
    'http://br.web.img2.acsta.net/c_520_690/newsv7/15/02/06/17/22/496087.jpg' 
 
]; 
 
var hrefs=["http://www.google.com","http://www.msdn.com","http://www.yahoo.com"] 
 

 
function slideShowForward() { 
 
    images.push(images.shift()); 
 
    hrefs.push(hrefs.shift()); 
 
    document.getElementById('imagesP').style.backgroundImage = 'url(' + images[0] + ')'; 
 
    document.getElementById('imagesP').setAttribute(href,hrefs[0]); 
 
} 
 

 
function slideShowBack() { 
 
    images.unshift(images.pop()); 
 
    hrefs.unshift(hrefs.pop()); 
 
    document.getElementById('imagesP').style.backgroundImage = 'url(' + images[0] + ')'; 
 
    document.getElementById('imagesP').setAttribute(href,hrefs[0]); 
 
} 
 
window.onload=function() { 
 
    document.getElementById('imagesP').onclick=function(e) { 
 
    var tgt = e.target||e.srcElement; 
 
    if (tgt.tagName.toLowerCase()=="input") e.preventDefault(); 
 
    else location=this.getAttribute("href"); 
 
    } 
 
}
#imagesP { border: 1px solid black; height: 200px; width:750px; background-image: url(http://br.web.img2.acsta.net/c_520_690/newsv7/15/02/06/17/22/496087.jpg)}
<div id="imagesP" href="http://www.google.com"> 
 
    <div id="form"> 
 
    <input type="button" value="previous" onclick="slideShowBack();" style="width: 39px; height: 34px;" /> 
 
    <input type="button" value="next" onclick="slideShowForward();" style="width: 39px; height: 34px;" /> 
 
    </div> 
 
</div>

+0

謝謝,但只有一個鏈接正在運行谷歌 –

+0

由於安全原因,Google和其他人可能無法在代碼段中執行此操作 - 但是我也使用了奇怪的數組處理功能,以免發生太多變化。應該工作 – mplungjan