<style type="text/css">
#thebar
{
top:10px;
left:200px;
width:40px;
cursor:hand;
position:absolute;
background:#808080;
height:100%;
}
</style>
<script>
function kk()
{
var obj = document.getElementById("thebar");
document.all.ss.value = obj.offsetWidth;
alert(obj.id);
alert(obj.offsetWidth);
}
</script>
<div id="thebar" onclick="kk()">sssss</div>
<input type="text" name="ss" value="" />
#thebar
{
top:10px;
left:200px;
width:40px;
cursor:hand;
position:absolute;
background:#808080;
height:100%;
}
</style>
<script>
function kk()
{
var obj = document.getElementById("thebar");
document.all.ss.value = obj.offsetWidth;
alert(obj.id);
alert(obj.offsetWidth);
}
</script>
<div id="thebar" onclick="kk()">sssss</div>
<input type="text" name="ss" value="" />
我是想如何get和set这个"thebar"对象在<style>里定义的属性
var par=document.styleSheets[0].rules.item(0).style.width;
alert(par);
function kk()
{
var obj = document.getElementById("thebar");
var style = obj.currentStyle||obj.style
alert(style.width);
}
</script>
照您的方法只能在ie下显示,fireFox提示说没有这个方法
<style type="text/css">
#thebar
{
top:10px;
left:200px;
width:30px;
cursor:hand;
position:absolute;
background:#808080;
height:100%;
}
</style><script>
function kk()
{
var obj = document.getElementById("thebar");
alert(obj.id);
var style = obj.currentStyle||obj.style;
alert(style.width);
}
</script><div id="thebar" onclick="kk()">click</div>
再通过这个元素取到<style></style>里定义的#thebar的width
请问这样有办法实现吗?另外我想我可能是概念错了,可能把这个理解成对象了,如果说<div id="thebar">和<style></style>是两码事,那么怎么通过js获得<style></style>标签里定义的值呢?比如说#thebar,#thebar下的width