Javascript中如何调用外部CSS中的一个STYLE

dream1889 2010-06-10 12:32:31
.html部分代码
<div id="divButton">放按钮控件的</div>

.css部分代码
#divButton
{
width:100px;
height:100px;
overflow:hidden;
left:100px;
top:100px;
/*……有很多属性*/
}

.js部分代码
var e=document.getElementById("divButton");
document.write(e.currentStyle["width"]);//可输出100px

//本人想显示#divButton中的所有信息应该怎么调用?
...全文
213 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
weewcoc 2010-06-11
  • 打赏
  • 举报
回复
jquery 果然很好用啊 最近也在学 

jquery效果在线演示
l6801567 2010-06-10
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 stayalive 的回复:]

HTML code

<!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>
<meta http-equ……
[/Quote]
xk1126 2010-06-10
  • 打赏
  • 举报
回复
var e=document.getElementById("divButton");
for(var i in e.currentStyle){
document.write(i+":" + e.currentStyle[i] + "<br>");
}
currentStyle代表了在全局样式表、内嵌样式和 HTML 标签属性中指定的对象格式和样式。

stayalive 2010-06-10
  • 打赏
  • 举报
回复

<!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>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档</title>
<style type="text/css">
#divButton
{
width:100px;
height:100px;
overflow:hidden;
left:100px;
top:100px;
}
</style>
</head>
<body>
<div id="divButton">tttttttttttttt</div>
<script type="text/javascript">
var e=document.getElementById("divButton");
for(var i in e.currentStyle){
document.write(i+':'+e.currentStyle[i]+'<br />');
}
</script>
</body>
</html>
a5692408b 2010-06-10
  • 打赏
  • 举报
回复
你直接用Jquery 框架吧 这个很方便的 不用写很多代码

比如 你这个
用Jquery 框架
$("#divButton").css("width","100");

""代表你的样式的名字,""代表你修改的样式

就可以变成100 还很很多这个的例子

JavaScript不用深学 能用就行 除非你很像研究它
dream1889 2010-06-10
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 xk1126 的回复:]
var e=document.getElementById("divButton");
for(var i in e.currentStyle){
document.write(i+":" + e.currentStyle[i] + "<br>");
}
currentStyle代表了在全局样式表、内嵌样式和 HTML 标签属性中指定的对象格式和样式。
[/Quote]
提示:没有权限
错误行:for(var i in e.currentStyle)
//本人ie6.0浏览器

87,910

社区成员

发帖
与我相关
我的任务
社区描述
Web 开发 JavaScript
社区管理员
  • JavaScript
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧