我想要的效果是,创建一个元素LI,然后获取刚刚阶建这个元素样式表中的width ,我现在弄出来老是有错,但我又不知道为什么,求大神帮看看我到底哪里写错了,应该怎么改,谢谢哈。
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<style>
li{
width: 300px;
height: 20px;
background: #002299;
position: absolute;
left: 0px;
}
div{
width: 30px;
}
</style>
<title></title>
<script>
function clsDiv(xd,classx){
var xDi = document.createElement("li");
xDi.className =" ";
if(xd){
xDi.style.width =xd;
if(xDi.className == ""){
xDi.className = classx;
}
else{
xDi.className = classx + "sd";
}
}
return xDi;
};
function classNamex(DIVs,cel){
if(window.getComputedStyle){
return parseFloat(DIVs.getComputedStyle(DIVs,null)[cel]);
}
else{
return parseFloat(DIVs.currentStyle[cel]);
}
};
//
//
window.onload = function(){
var sdd = clsDiv("30px","sidw");
console.log(sdd);
console.log(sdd.style.width = classNamex(sdd,"width"));
};
</script>
</head>
<body>
</body>
</html>