当在浏览器的控制台中执行相同的js代码时工作正常,但在浏览器中始终显示
时无法正常运行未捕获的TypeError:无法读取null的属性“ classList”
[
{},
{},
{}
]
html
<script type="text/javascript">
var wid = window.screen.availWidth;
if(wid<375){
document.getElementById('img').classList.remove('fa-5x');
document.getElementById('img').classList.addClass('fa-3x');
document.getElementsByTagName('h3').setAttribute('font-size',"1em")
}
</script>
css
<div class="logo" id="logo">
<i class="fa fa-university fa-5x" id="img" style="color:#ac9766; text-shadow:3px 3px 3px #fff;"></i>
</div>