document.getElementById("bottom").style.top = 120px;js可以这样改变css的边距但是不可以 document.getElementById("bottom").style.marginTop = 120px;这样,怎么回事啊那遇到margin-top的时候怎么修改css的边距那?
document.getElementById("bottom").style.top = 120px;js可以这样改变css的边距但是不可以 document.getElementById("bottom").style.marginTop = 120px;这样,怎么回事啊那遇到margin-top的时候怎么修改css的边距那?
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
<title>无标题页 </title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><script type="text/javascript">
window.onload = function(){
document.getElementById('click').onclick = function(){
var div = document.getElementById('div');
div.style.marginTop = '1000px';
alert(div.style.marginTop);
};
};
</script>
</head>
<body>
<div id="div" style="margin-top:10px;"></div> //把margin-top写在标签里
<input id="click" type="button" onclick="aa()" value="click" />
</body>
</html>
<div style="border:solid 1px #09f;" id="div1">
<input type="button" id="btnSetStyle" value="设置上边距"/>
</div>
<script type="text/javascript">
var $=function() {return document.getElementById(arguments[0]);}
$("btnSetStyle").onclick=function() {
$("div1").style.marginTop="130px";//lz可能你这里没加引号的原因
}
</script>
or
div.style.marginTop = 1000;
1,在JS中是区分大小写的;2,JS约定不同的词组合成关键JS字时首字母大写,除了开头的;比如getElementById(),marginTop等等3,值结果要加引号,就可以了
document.getElementById("bottom").style.top = "120px";
document.getElementById("bottom").style.marginTop = "120px";