JavaScript style.height 不起作用
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/20375317/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-27 18:21:16 来源:igfitidea点击:
JavaScript style.height not working
提问by user3065665
I'm trying to set the height of div on my page, because my page content is dynamic. But it don't work.
我正在尝试在我的页面上设置 div 的高度,因为我的页面内容是动态的。但它不起作用。
CSS:
CSS:
<style type="text/css">
#figmenu {
height: 50px;
}
</style>
JS:
JS:
<script type="text/javascript">
function HeightUp() {
var fm = document.getElementById('figmenu');
fm.setAttribute('style', 'height: 500px');
// fm.style.height = '500px';
}
</script>
HTML:
HTML:
<body>
<div id='cssmenu' onclick=HeightUp();>
<input type="submit" name="change" value="First Button" id="figs"/>
<input type="submit" name="change" value="Second Button" id="tr"/>
<input type="submit" name="change" value="Third Button" id="fbp"/>
</div>
<div id='figmenu'>
<input type="submit" name="change" value="4th Button" id="b4"/>
<input type="submit" name="change" value="5th Button" id="b5"/>
<input type="submit" name="change" value="6th Button" id="b6"/>
</div>
</body>
回答by Shryme
回答by yokesh ganesan
check whether the page has any other html element contains same id name "figmenu"
检查页面是否有任何其他 html 元素包含相同的 id 名称“figmenu”
in a page there should not be two ids with a same name
在一个页面中不应有两个同名的 id