首页 > 其他 > 详细

document的属性操作

时间:2015-09-14 00:22:40      阅读:294      评论:0      收藏:0      [点我收藏+]

document对象:

1.直接操作:

对象.属性 = 值;

如下面一段代码:

<a href  = "...">跳转</a>

<script>

    var a = document.getElenmentsByTagName("a")[0];//注意这里的TagName是个数组,所以用数组的方式填写;

    a.href = "...";

    a.className = "...";

    a.getAttribute("href");//获取值;

    a.setAttribute("href","3.html");//设置值;

</script>

2.document的样式操作:

div.style.backgroundColor = "black";

div.style.color  = "white";  

3.使用hover:

a.mouseover = function () {

  this.style.backgroundColor = "red";

};

a.onmouseout = function () {

  this.style.color = "blue";//this指鼠标正在指的这个..

};

document.styleSheets[index].rule[index].style.属性;

document.styleSheets[index].cssRules[index].style.属性;(FF);

获取最终样式:

var div1 = document.getElementById("div1");

<script>

  alert(div1.currentStyle.width);(IE)

  //alert(window.getcoputeStyle(div1,null)[width]); other

 

document的属性操作

原文:http://www.cnblogs.com/lihanqiang/p/4805867.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!