JS基础学习(十)
来源:互联网 发布:手机网页源码怎样测试 编辑:程序博客网 时间:2024/05/22 17:40
4:(1)DOM对CSS进行操作
box1.style.width="400px";
box1.style.height="400px";
box1.style.backgroundColor="yellowgreen";
//JS改变的样式会成为内联样式而覆盖当前样式表的样式;
但是如果样式表使用!important,则不能被覆盖;
alert(box1.currentStyle.backgroundColor);
alert(window.getComputedStyle(box1,null).backgroundColor);
通过currentStyle,getComputedStyle(),获取的CSS样式不能修改只能读取,style读取的样式可以进行修改。
(1) 兼容性问题的解决
functiongetStyle(obj , name){
if(window.getComputedStyle){
//正常浏览器的方式,具有getComputedStyle()方法
returngetComputedStyle(obj , null)[name];
}else{
//IE8的方式,没有getComputedStyle()方法
returnobj.currentStyle[name];
}
//returnwindow.getComputedStyle?getComputedStyle(obj ,null)[name]:obj.currentStyle[name];
(2) 元素的属性:
1:clientwidth:当前宽度,不会返回单位只会返回具体的数字;clientheight:会获取元素的高度和宽度包括内容区和内边距这些属性可读,但是不能修改。
2:offsetheight,offsetwidth,获取高度和宽度,或获取所有的大小包括边框;
3:offsetparent可以获取当前元素的定位父元素,返回开启了定位的父元素(position),如果都没有开启默认返回body元素;
4:scrollheight:滚动条的高度 ,scrollwidth:滚动条的宽度, scrollleft:滚动条滚动的距离,
ScrollTop:垂直滚动的距离。if(this.scrollHeight-this.scrollTop==this.clientHeight)
<!DOCTYPE html><html><head><meta charset="UTF-8"><title></title><style type="text/css">p{width: 300px;height:500px;background-color: #BBFFAA; overflow: auto;}</style><script type="text/javascript">//为id=info 标签来绑定一个滚动的事件;window.onload=function(){var info =document.getElementById("info");var inputs=document.getElementsByTagName("input");//onscroll事件 :该事件会在元素的滚动条滚动的时候触发;info.onscroll=function(){//当滚动条滚动到底的时候;if(this.scrollHeight-this.scrollTop==this.clientHeight) { //表单项可用; inputs[0].disabled=false; inputs[1].disabled=false; };}};</script></head><body><h3>欢迎亲爱的用户注册!</h3><p id="info">//文字自行补充;</p><!--disabled="disabled"表单将变成不可用的--><input type="checkbox" disabled="disabled"/>我已经阅读此协议一定遵守<input type="submit" value="注册" disabled="disabled"/></body></html>
- JS基础学习(十)
- XML学习基础(十)
- Css基础学习(十)—思考
- VBS学习日记(十) WMI 基础
- UI基础学习之(十):UIPageControl
- HTML5基础学习笔记(十)
- HTML5基础学习笔记(二十)
- java基础学习(十)容器-1
- html和CSS基础学习(十)
- 0基础lua学习(十)迭代器
- HTML基础学习 十
- javascript基础十(知识点类js中的跨域)
- JS基础学习(四)
- JS基础学习(六)
- JS基础学习(八)
- JS基础学习(九)
- Linux学习基础篇(十)
- Linux学习基础篇(十)
- (二十五)基础系列 数据库
- Mac OS 批量删除短信
- 以前学习JAVA时接触到的基础知识(一)
- commons-configuration2:properties文件写入中文(no escape)
- 替换空格
- JS基础学习(十)
- office怎么也卸载不干净,解决办法
- Qt5.6.0 移植到ARM(tq2440)步骤及问题记录
- codeforces C. Marco and GCD Sequence
- LeetCode 461. Hamming Distance
- 网易云课堂\『李兴华java培训23』MongoDB数据库\章节2课时20游标.sql
- 关于c语言中的运算符及注意事项
- WEB 前端菜鸟,感觉很迷茫,该怎么做?
- php_note