注意 是javascript 脚本语言的哦 获取ID, 然后,给DIV高度取赋值,每次增加10。
var dobj = document.getElementById(obj);
alert(dobj.style.height); dobj.style.height = dobj.style.height + 10;
现在出现的问题是: 第一此赋值成功,第二次就出现错误了。 提示参数错误。
有一点有点奇怪。我是CSS初始的 高度是50px. 但是我是alert();获取,第一次是空。然后赋值成功。第二次获取到alert(); 输出的是 10px 然后再赋值就出错了。
alert(dobj.style.height); dobj.style.height = (parseInt(dobj.style.height) + 10)+"px";
<script language='javascript'>
function fun(){
var dobj = document.getElementById('obj');
alert(dobj.style.height);
dobj.style.height = (parseInt(dobj.style.height) + 10)+"px";
}
</script>
<div id="obj" style="background-color:red;height=50"><input type='button' onclick="fun();"></div>