属性读写操作注意事项
2016-07-06 10:08
246 查看
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title></title> <script> window.onload =function() { var oBtn1 = document.getElementById('btn1'); var oBtn2 = document.getElementById('btn2'); var oRed = document.getElementById('red1'); var oYellow = document.getElementById('yellow1'); var Op = document.getElementById('p1'); var num = 15; oBtn1.onclick = function() { num++; //JS中不允许出现“-”,后面单词第一个字母大写。 eg:font-size:fontSize padding-top:paddingTop Op.style.fontSize = num+'px'; }; oBtn2.onclick = function() { num--; Op.style.fontSize = num+'px'; }; oRed.onclick = function(){ /* 太过于复杂,建议把一下代码写到样式表里去。 Op.style.width = '300px'; Op.style.background = 'yellow'; Op.style.border = '10px solid #ccc' Op.style.padding = '20px'; Op.style.color = 'red'; class 保留字 关键字:var function class =>className*/ Op.className = 'red'; }; oYellow.onclick = function() { Op.className = 'yellow'; }; }; </script> <style> .red{width:300px;background: pink;border: 10px solid #ccc;padding:20px;color:yellow;} .yellow{width:300px;background: yellow;border: 10px solid #ccc;padding:20px;color:black;} </style> </head> <body> <input id="btn1" type="button" value="+"/> <input id="btn2" type="button" value="-"/> <input id="red1" type="button" value="红"/> <input id="yellow1" type="button" value="黄"/> <p id="p1" >大家好~</p> <!--此处不需要加类名 即,class = "red";--> </body> </html>
相关文章推荐
- String字符串的使用
- 开启“树”之旅
- iOS求职之OC面试题
- this a a mark down test
- java实现单一登录 踢人效果
- mybatis 使用小结
- centos7 安装Tomcat7
- csdn的本土产品c-ide
- PHP 获取 今日 本月 上月
- 华为机试---成绩排序
- 算法的复杂度
- 个人档案 7-5
- CSS 中文字体 Unicode 编码表
- JQuery中$.ajax()方法参数详解
- Regular Expression Matching
- POJ1458【最长公共子序列】
- 在线渗透工具大全
- myeclipse 10破解办法
- float与double的范围和精度
- 在C++中用虚函数的作用是什么?为什么要用到虚函数