<style type="text/css">
ul{
}
li{
border:1px solid gray;
list-style:none;
float:left;
width:110px;
}
.txt{
padding:4px;
background-color:#ffffff
}
.title{
font:12px;
background-color:"#DEF1FF";
}
</style><ul>
<li><div></div>
<li><div></div>
</ul>
样式有对li的width设置值,
为什么用js 获取不到呢
ul{
}
li{
border:1px solid gray;
list-style:none;
float:left;
width:110px;
}
.txt{
padding:4px;
background-color:#ffffff
}
.title{
font:12px;
background-color:"#DEF1FF";
}
</style><ul>
<li><div></div>
<li><div></div>
</ul>
样式有对li的width设置值,
为什么用js 获取不到呢
<head><SCRIPT LANGUAGE="JavaScript">
<!--
function getWidth()
{
alert(document.getElementById("aaa").style.width);
}
//-->
</SCRIPT>
</head>
<body>
<ul>
<li id="aaa" style="width:110px;"> <div> </div> </li>
<li> <div> </div> </li>
</ul>
<input type="button" value="clickButton" onclick="getWidth()"/></body>
</html>
可以取到值,你的css看看写的有没有问题。js肯定是可以拿到值的
要是你用jquery就更方面了
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Untitled Document</title>
</head>
<style type="text/css">
ul {
}
li {
border: 1px solid gray;
list-style: none;
float: left;
height: 40px;
width: 110px;
} .txt {
padding: 4px;
background-color: #ffffff
} .title {
font-size: 12px;
background: #DEF1FF;
}
</style>
<SCRIPT LANGUAGE="JavaScript">
<!--
function test(){
alert(document.getElementsByTagName("li")[0].currentStyle.width);
}
//-->
</SCRIPT>
<body>
<ul>
<li>
<div>
</div>
</li>
<li>
<div>
</div>
</li>
</ul>
<input type="button" value="clickButton" onclick="test()"/>
</body>
</html>
if(elem.style[name])
return elem.style[name];
else if(elem.currentStyle)
return elem.currentStyle[name];
else if(document.defaultView&&document.defaultView.getComputedStyle){
name=name.replace(/([A-Z])/g,"-$1");
name=name.toLowerCase();
var s=document.defaultView.getComputedStyle(elem,"");
return s && s.getPropertyValue(name);
}
else
return null;
}
你看看jquery的文档