js控制CSS
来源:互联网 发布:仿淘宝购物车代码 编辑:程序博客网 时间:2024/04/30 02:07
<!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>JS调用CSS</title>
<style>
#dStyle{
width:500px;
height:400px;
background-color:#F00;
}
.dStyle{
width:500px;
height:400px;
background-color:#F00;
}
.dStyle2{
width:500px;
height:400px;
background-color:#0F0;
}
.oldStyle{
font-size:20px;
color:#309;
}
.newStyle{
font-size:80px;
color:#309;
}
</style>
<script>
function changeColor(){
var obj = document.getElementById("d");//找到要改变样式的对象div
//obj.style.backgroundColor = "green";//指定一种样式 ,
//obj.style.color = "blue";
//如果这个样式比较多,有20个,就将所有的样式用.写好,直接调用
obj.className ="dStyle2";
}
function bigger(){
var obj = document.getElementById("f");
obj.className = "newStyle";
}
function simmer(){
var obj = document.getElementById("v");
//alert(obj.style.fontSize);
var obj2 = obj.style.fontSize;
var obj3 = obj2.substr(0,obj2.length-2);
obj.style.fontSize = (obj3-10)+"px";
}
</script>
</head>
<body>
<input type="button" value="绿色" onclick="changeColor()" />
<input type="button" value="变大" onclick="bigger()" />
<input type="button" value="变小" onclick="simmer()" />
<div id="d" class="dStyle"></div>
<div id="f" class="oldStyle">一段文字</div>
<div id="v" style="font-size:100px">点我我就变小!</div>
</body>
</html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>JS调用CSS</title>
<style>
#dStyle{
width:500px;
height:400px;
background-color:#F00;
}
.dStyle{
width:500px;
height:400px;
background-color:#F00;
}
.dStyle2{
width:500px;
height:400px;
background-color:#0F0;
}
.oldStyle{
font-size:20px;
color:#309;
}
.newStyle{
font-size:80px;
color:#309;
}
</style>
<script>
function changeColor(){
var obj = document.getElementById("d");//找到要改变样式的对象div
//obj.style.backgroundColor = "green";//指定一种样式 ,
//obj.style.color = "blue";
//如果这个样式比较多,有20个,就将所有的样式用.写好,直接调用
obj.className ="dStyle2";
}
function bigger(){
var obj = document.getElementById("f");
obj.className = "newStyle";
}
function simmer(){
var obj = document.getElementById("v");
//alert(obj.style.fontSize);
var obj2 = obj.style.fontSize;
var obj3 = obj2.substr(0,obj2.length-2);
obj.style.fontSize = (obj3-10)+"px";
}
</script>
</head>
<body>
<input type="button" value="绿色" onclick="changeColor()" />
<input type="button" value="变大" onclick="bigger()" />
<input type="button" value="变小" onclick="simmer()" />
<div id="d" class="dStyle"></div>
<div id="f" class="oldStyle">一段文字</div>
<div id="v" style="font-size:100px">点我我就变小!</div>
</body>
</html>
0 0
- JS控制CSS
- JS控制CSS
- js控制css总结
- js控制css样式
- css&js 控制输入
- js控制CSS
- css+js控制图片展示
- css+js控制图片展示
- CSS+JS控制字体闪烁
- JS 控制 CSS 样式表
- JS控制CSS样式大全
- JS、CSS控制滚动条显隐
- js实现控制css样式
- CSS+JS控制字体闪烁
- js,css文件版本号控制
- JS 控制CSS样式表
- javascript 控制css js控制 clss
- js控制重新加载css和js
- Bone Collector 01背包模板
- 剑指offer-用两个栈实现队列
- html基本用法
- 【JS】—— HTML DOM基础
- 1032. Sharing
- js控制CSS
- 博弈论
- cigarettes
- 2017年2月18日小总结
- JSP综合项目实战 实现商品的动态显示,查看商品信息,保留浏览记录
- js实现3秒后自动跳转
- Python爬虫获取图片并下载保存至本地
- JS网页触发事件
- 06-图2 Saving James Bond - Easy Version (25分)