如何用attachEvent动态的控制table的显示

要实现根据[b]选择的select的值对应显示相应的table[/b],为什么不能用?代码有错吗?
[code="html"]


<br> function show(){<br> var item = document.getElementById(&quot;s&quot;);<br> if(item.value == &quot;1&quot;){<br> document.getElementById(&quot;t1&quot;).style.visibility = &quot;visibile&quot;;<br> }else if(item.value == &quot;2&quot;){<br> document.getElementById(&quot;t2&quot;).style.visibility = &quot;visibile&quot;;<br> }<br> }<br> document.getElementById(&quot;s&quot;).attachEvent(&quot;onchange&quot;,show);<br>
<body>
    <select id="s">
        <option value="1">table1</option>
        <option  value="2">table2</option>
    </select>
    <br/>
    <br/>
    <br/>
    <table border=1 id="t1" style="visibility:hidden">
        <tr><td>1</td></tr>
    </table>
    <table border=1 id="t2" style="visibility:hidden">
        <tr><td>2</td></tr>
    </table>
</body>


[/code]
用[b]CSS[/b]能实现吗?

你的代码有以下三点问题:
1、中代码的编译顺序问题。因为你是加在<header>中,所以会在页面初始化完成之间先编译了,因此document.getElementById(&quot;s&quot;).attachEvent(&quot;onchange&quot;,show); 你这个地方应该会报错,因为页面上还没初始化select标签,所以找不到id=s的标签</p> <p>2、因为你用的是attachEvent绑定事件,所以你的程序只能用ie,为了跨浏览器,还得加判断用addEventListener</p> <p>3、.style.visibility = &quot;[color=red]visibile[/color]&quot; 这个地方的单词你拼错了吧,应该是[b]visible[/b]</p>