简体   繁体   中英

Javascript setAttribute in IE9

So I'm trying to make a table hidden when the webpage opens but when a is clicked it should show but I'm having problems with IE9. I read that IE8 and below do not support setAttribute and my webpage seems to work correctly with Firefox. Here is the code, just wondering if anyone could help me out:

<h1 onclick="myFunction()">Show Sitemap</h1>

<table id="myInput" style="visibility:hidden;" width="100%" height="50%">
<tr><td><p>Test</p></td></tr>
</table>

<script>
function myFunction()
{
document.getElementById("myInput").setAttribute("style","visibility:visible;"); 
};
</script>

Try using

function myFunction()
{
    document.getElementById("myInput").style.visibility = "visible"; 
};

instead, as IE is more compatible with this.
Fiddle: http://jsfiddle.net/E396D/

I tried this in IE10 with compatibility mode on and it worked (the original didn't).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM