我需要更改span類標記的類別u的內容,當某人點擊p標記時,它們各自的id標記將作爲參數傳遞給函數,以便函數可以轉換將該數字轉換爲數字,並訪問數組中的數值,並將該數字作爲新值添加,完全替換之前的值。jquery從點擊數組中更改跨度標記內容
//html code
<span id="u">My point</span>
<p class="current" id="one" onclick="chan('one')">My point</p>
<p id="two" onclick="chan('two')">text2</p>
<p id="three" onclick="chan('three')">text2</p>
<p id="four" onclick="chan('four')">text2</p>
<p id="five" onclick="chan('five')">text2</p>
<p id="six" onclick="chan('six')">text2</p>
<p id="seven" onclick="chan('seven')" >text2</p>
//javascript code
var titl = ['My point',
'text2',
'text3',
'text4',
'text5',
'text6',
'text7'
];
function chan(pin){
if(pin="two"){
it = 1;
}
else if(pin="one"){
it = 0;
}
else if(pin="three"){
it = 2;
}
else if(pin="four"){
it = 3;
}
else if(pin="five"){
it = 4;
}
else if(pin="six"){
it = 5;
}
else if(pin="seven"){
it = 6;
}
document.getElementById("u").innerHTML = titl[it;
}
謝謝.. !!!有效 – xxCodexx