2010-02-08 44 views
0

所以我試圖完成一些JavaScript和編碼鏈接更新圖像時出現問題。在使用我的腳本的父窗口中,我打開一個遠程子窗口來操作圖像。在子窗口上的鏈接打開第一個圖像和最後一個圖像。另外兩個鏈接控制「下一個」圖像和之前的圖像。使用子窗口中的數組元素來更改父窗口中的圖像getElementById

繼承人是我迄今爲止

HTML父窗口:(還沒有想出如何發佈HTML放在這裏順便說一句:()

<html> 
    <head> 
    <title> </title> 
    <script type="text/javascript" src="scriptss.js"> 
    </script> 
    </head> 
    <body> 
    <img src="images/img0.jpg" width="200px" height="200px" id="myImage"  name="myImage" /></img> 
    <h1>XXX</h1> 
    <a href="#" id = "opens" >open</a> 
    </br> 
    <a href="#" id="closes">close</a> 
    </br> 
    </body> 
    <html> 

子窗口HTML:

<html> 
<head> 
    <title> Matt Beckley Assignment Remote</title> 
    <link rel="stylesheet" type="text/css" href="remote.css" /> 
<script type="text/javascript" src="scriptss.js"> 
</script> 
</head> 
    <body> 
    <h1>My Remote</h1> 
    <a href="#" id="first" onclick="first()">First Image</a> 
    </br> 
    <a href="#" id="next">Next Image</a> 
    </br> 
    <a href="#" id="previous">Previous Image</a> 
    </br> 
    <a href="#" id="last">Last Image</a> 
    </br> 
    <a href="#" id="closess">close</a> 
    </body> 
    </html> 

JAVASCRIPT子節點

var newWindow = null; 
    window.onload = init; 
    var myImages = new Array(); 

    //start loop - length depends on how many images you need to preload 
    for (var i=0; i<5; i++) { 
    //create new image object 
    var tempImage = new Image(); 
    //assign name|path of image to src property of image object 
    tempImage.src = "img" + (i+1) + ".jpg"; 
    } 


function init() 
{ 
for(var i=0; i<document.links.length; i++) 
{ 
document.links[i].onclick = changeWindowState; 
} 

} 

function windowOpen(){ 
if(newWindow && !newWindow.closed){ 
    return true; 
} 
return false; 
} 


function changeWindowState() 
{ 
if (this.id =="closes") 
{ 
    if(windowOpen()) 
    { 
     newWindow.close(); 
    } 
    else 
    { 
     alert("The window isn't open"); 
    } 
} 
if (this.id =="closess") 
{ 
    if(windowOpen()) 
    { 
     remotetest.html.close(); 
    } 
    else 
    { 
     alert("The window isn't open"); 
    } 
} 
if(this.id == "opens") 
{ 
    if(windowOpen()) 
    { 
     alert("The Window is alreadyopen!"); 
    } 
    else 
    { 
    newWindow = window.open ("remotetest.html","remoteWin","resizeable=no,width=200,height=200"); 
    } 
} 
return false; 
} 



function first() 
{ 
if(this.id == "first") 
{ 
alert("box"); 
} 
else(this.id == "first") 

{ 
alert("box"); 

} 
} 

無論如何,我正在預加載我的圖像,我弄明白了。我試圖訪問圖像標記中父節點中的元素,並顯示數組元素1-6。換句話說,圖像1到圖像6 想法是按下子節點中的按鈕並顯示第一個圖像元素[0],然後按另一個按鈕元素[5] 或按下另一個按鈕用於下一個元素[i + 1 ]與另一個按鈕。謝謝您的幫助。

回答

相關問題