<p id="t1">第一題您選擇的是<strong><u id="ss"></u></strong></p>
<ul id="choose1">
<li id="a1">哈哈</li>
<li id="a2">呵呵</li>
<li id="a3">嘿嘿</li>
<li id="a4">吼吼</li>
</ul>
<p id="t2">第二題您選擇的是<strong><u id="cc"></u></strong></p>
<ul id="choose2">
<li id="b1">java</li>
<li id="b2">ios</li>
<li id="b3">Android</li>
<li id="b4">php</li>
<li id="b5">jquery</li>
</ul>
window.onload = function(){
var aLi = document.getElementById('choose1').getElementsByTagName('li');
var bLi = document.getElementById('choose2').getElementsByTagName('li');
for(var i = 0;i<=aLi.length;i++){
aLi[i].onclick = function(){
var aTxt = this.innerHTML;
document.getElementById('ss').innerHTML = aTxt;
}
}
for(var j = 0;j<=bLi.length;j++){
bLi[j].onclick = function(){
var bTxt = this.innerHTML;
document.getElementById('cc').innerHTML = bTxt;
}
}
}
我想把兩道題的選擇結果都打印到響應的位置,但每次只能打印上第一題,把第一題注釋掉,第二題才可以打印上,是邏輯上 有什麼問題麼?
for(var i = 0;i<aLi.length;i++){//多了一個=號
aLi[i].onclick = function(){
var aTxt = this.innerHTML;
document.getElementById('ss').innerHTML = aTxt;
}
}
for(var j = 0;j<bLi.length;j++){//多了一個=號
bLi[j].onclick = function(){
var bTxt = this.innerHTML;
document.getElementById('cc').innerHTML = bTxt;
}
}
}