<select id="xl1" onchange="change()" ><option >第一</option><option>第二</option></select><select id="xl2" onchange="change()" ><option >第一</option><option>第二</option></select>如果只有選擇id=xl1中的“第二”才能顯示出來id=xl2中的<select>我改怎么做?我沒分,我不過真是再這里卡住了,謝謝各位
2 回答

慕慕森
TA貢獻(xiàn)1856條經(jīng)驗(yàn) 獲得超17個(gè)贊
<script type="text/javascript">
(function() {
var xl1,xl2
window.onload = function() {
xl1 = document.getElementById("xl1");
xl2 = document.getElementById("xl2");
xl1.onchange = xl2.onchange = change;
showItem(xl2, xl1.selectedIndex === 1);
};
function change(e) {
var e = e || window.event;
if( this === xl1 ) {
var b = this.selectedIndex === 1;
showItem(xl2, b)
}
}
function showItem(el, b) {
el.style.visibility = b?"visible":"hidden";
}
})();
</script>