猿问

setAttribute为什么无法改变元素的宽高

代码如下
1.使用oUl.style.height='1000px'可以改变ul的高度,但是为什么使用oUl.setAttribute('height','1000px')却无法改变;
2.将“height”改成title后,也是有效果的。

<script>

    window.onload=function(){

        var oUl=document.getElementById('ul');

        oUl.setAttribute('height','1000px');

        // oUl.style.height='1000px';

    }

</script>

<body>

<ul id="ul">

    <li>1</li>

    <li>2</li>

    <li>3</li>

</ul>

</body>

阿晨1998
浏览 1326回答 1
1回答

慕沐林林

setAttribute()是用来设置element的属性值的,element没有height属性,你可以试一下oUI.setAttribute('style', 'height: 1000px');
随时随地看视频慕课网APP

相关分类

JavaScript
我要回答