我正在浏览jQuery函数。
让我们以此为例:
http://api.jquery.com/slideUp/
如果您在浏览器上执行“检查元素”,则可以看到div的高度发生变化。高度采用像素的十进制值。如何用javaScript做到这一点?
答案 0 :(得分:10)
不要在W3Schools上看东西,它们是一个不好的来源。一般来说,当你想知道这样的事情时,只需看看the specification。长度为<number>
s,可包括小数值。
答案 1 :(得分:0)
你可以这样写:
<script>
function auto(){
var obj=document.getElementById("d");
var height=parseFloat(obj.style.height);
obj.style.height=height-10+'px';
}
<button value="change" onclick="auto()"></button>
<div id="d" style="border:thick solid black;width:200px;height:200px;"></div>