js 怎么获取 css ?在线等待! 谢谢!
例如: 文件 “style.css” 里 “.style{color:red;} ” <div js事件> 鼠标移动 或 点击触发事件将改变css </div> 求助:js怎么获取css 文件里的属性?(不是通过HTML里的标签,是直接打开css文件,获取!)
追问:获取 css的, 连接css文件, 查找熟悉
例如: 文件 “style.css” 里 “.style{color:red;} ” <div js事件> 鼠标移动 或 点击触发事件将改变css </div> 求助:js怎么获取css 文件里的属性?(不是通过HTML里的标签,是直接打开css文件,获取!)
追问:获取 css的, 连接css文件, 查找熟悉
答案:js事件:
onmouseover="this.style.color='red';"
onclick="this.style.color='red';"
其他:<!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=utf-8" /> <title>无标题文档</title> <script type="text/javascript"> // JavaScript Document function changeColor(){ var f = document.getElementById('fontId').style.color = '#309'; //点击是切换颜色 } </script> </head> <body> <div id="testDiv" onclick="changeColor()"><font id="fontId" style="color:#F33"> 鼠标移动 或 点击触发事件将改变css </font></div> </body> </html> 额,css文件和js文件都是操作html文件的,他们两个怎么可以互相获取呢,在js代码中使用"对象.style.属性(要设置的)="你要设置的值""而且这个属性是css中的属性, 粘下来看看是你要的效果么? <!DOCTYPE html> <html dir="ltr" lang="zh"> <head> <meta charset="utf-8" /> <title>Template_html5</title> <style> #test{width:100px; height:100px; border:#f00;} .on{background:#690;} .out{background:#000;} </style> </head> <body> <div id="test"></div> <script> (function () { $('test').onmouseover = function () { this.className = 'on'; } $('test').onmouseout = function () { this.className = 'out'; } })(); function $(id) { return document.getElementById(id); } </script> <body> </html> <script> 标签里面的东西可以站出来,放在test.js里面,然后在div下用这段代码引入 <script src="test.js"></script>
上一个:如何用CSS来分别控制TD内的文字和DIV两种元素的定位和大小,在线等高手帮忙
下一个:在DIVCSS布局里面这margin:0 auto; width:990px; height:300px; overflow:hidden;} float:left; 什么意思?