利用JS设置元素style属性:最小高度隐藏

JavaScript07

利用JS设置元素style属性:最小高度隐藏,第1张

最小高度:Object.style.minHeight=length

隐藏元素:Object.style.display=none

其他属性参考: http://www.w3school.com.cn/jsref/dom_obj_style.asp

火狐浏览器默认把可视区域的高度设为0,这样的话,$(window).height()就等于0了。在css的开头位置添加下面一行,即可兼容所有浏览器:html, body {width:100%height:100%}

<!doctype html>

<html>

<head>

<meta charset="UTF-8">

<meta name="Generator" content="EditPlus®">

<meta name="Author" content="">

<meta name="Keywords" content="">

<meta name="Description" content="">

<title>Document</title>

</head>

<body>

<div id = "box"></div>

</body>

<script type="text/javascript">

var box = document.getElementById("box")

box.style.width='100px'

box.style.height='200px'

box.style.backgroundColor='red'

</script>

</html>