2012-04-26 42 views
0

我正在尋找一種JavaScript,允許圖像/字符顯示不同的信息,具體取決於它們在單擊時所處的章節。例如,在一個章節我想字母A,顯示信息A.但在第2章我想字母A,顯示信息B.下面是當前的代碼,我有:按鈕是否可以在不同事件中更改其onClick信息

HTML:

//Chapters/Events where characters move. Need info to change on chapter move 
<a href="#" onclick= "chapter1();">1-prologue</a> 
<a href="#" onclick= "chapter2();">2</a> 
<a href="#" onclick= "chapter3();">3</a> 

//Characters moving on map that are onClick buttons to show info 
<a href="#"> 
<img id="tyrion-map" src="sm_tyrion.png" /></a> 
<a href="#"> 
<img id="catelyn-map" src="purple-small.png" /></a> 
<a href="#"> 
<img id="bran-map" src="yello-small.png" /></a> 

JS:

//tyrion 
var tyrion = null; 

//catelyn 
var catelyn = null; 

//bran 
var bran = null; 

function init(){ 

    "use strict"; 

    tyrion = document.getElementById("tyrion-map"); 
    tyrion.style.position= 'relative'; 
    tyrion.style.left = '50px'; 
    tyrion.style.top = '50px'; 

    catelyn = document.getElementById("catelyn-map"); 
    catelyn.style.position= 'relative'; 
    catelyn.style.left = '50px'; 
    catelyn.style.top = '50px'; 

    bran = document.getElementById("bran-map"); 
    bran.style.position= 'relative'; 
    bran.style.left = '50px'; 
    bran.style.top = '50px'; 

}

//Chapter 1- prologue 
function chapter1() { 

    "use strict"; 

    tyrion1(); 
    catelyn1(); 
    prologue1(); 
    dany1(); 
    bran1(); 
    jon1(); 
    eddard1(); 
    arya1(); 
    sansa1(); 
} 


//Chapter 2 
function chapter2() { 

    "use strict"; 

    tyrion2(); 
    catelyn2(); 
    dany1(); 
    bran2(); 
    jon2(); 
    eddard2(); 
    arya1(); 
    sansa1(); 
    prologue2(); 
} 


//Chapter 3 
function chapter3() { 

    "use strict"; 

    tyrion3(); 
    catelyn1(); 
    dany1(); 
    bran3(); 
    jon3(); 
    eddard3(); 
    arya1(); 
    sansa1(); 
    prologue2(); 
} 
+2

你的問題是什麼? – 2012-04-26 21:03:58

回答

0

我不知道確切的情況下/章節的事情,但看起來你正在控制改變章節和onclick章節顯示。所以當改變章節時,設置一個變量例如上chapter1()

current_chapter = 1 

基於有關該章current_chapter顯示信息值被點擊圖像然後當。

相關問題