<html>
<style type="text/css">
a {
display: none;
}
</style>
<body>
<p id="p"> a paragraph </p>
<a href="http://www.google.com" id="a">google</a>
</body>
<script type="text/javascript">
var a = (document.getElementById('a')).style;
alert(a.display);
var p = (document.getElementById('p')).style;
alert(p.display);
p.display = 'none';
alert(p.display);
</script>
</html>
Run Code Online (Sandbox Code Playgroud)
第一个和第二个alert显示只是一个空字符串,我认为应该是none和block.然而,在内部display设置之后,第三个alert终于发出警报none.
但为什么?我怎样才能display正确检索属性?
谢谢.
为什么这段代码不起作用?
var all_obj_element= new Array();
all_obj_element[0]= document.getElementById('Img3');
alert(all_obj_element[0].style.width);
Run Code Online (Sandbox Code Playgroud)
警报显示一个空盒子!