zoukankan      html  css  js  c++  java
  • window.document对象的操作

    一、找到想要操作的对象

    1、document.getElementById("id");         根据id找,找到的是一个。

    2、document.getElementsByName("name");        根据name找,找出来的是数组。

    要给数组赋上事件必须进行循环遍历:

    var  arr =document.getElementsByClassName("div1");

    for(var i =0;i<arr.length;i++)

    {

       arr[i].onclick=function(){

         this.style.backgroundColor="red";                   //this 在循环中点谁谁变色

        }

    }

    3、document.getElementsByClassName("name");       根据classname找,找出来的是数组。

    4、document.getElementsByTagName("name")           根据标签名找,找出来的是数组。

    二、三个事件

    1、点击事件

    onclick

    2、鼠标移入事件

    onmouseover

    3、鼠标移出事件

    onmouseout

    三、控制标记的样式

    标记对象.style.样式="值";

    var a =document.getElementById("btn1");

    a.onclick=function(){

    a.style.backgroundColor="red";

    }

    注意:在样式里带“-”的,要将“-”去掉,并且将其之后一个字母变成大写

    在JS里对象的index属性,可以记录一个int类型的值

  • 相关阅读:
    平时用到的Linux命令
    angular.element方法汇总
    CSS display:inline-block
    CSS:position:fixed使用(转)
    常见浏览器兼容性问题与解决方案【转】
    部分浏览器兼容问题
    php对应js math.random
    php stdclass转数组
    写在2016年末
    VirtualBox中Ubuntu 14.04屏幕分辨率不能设置的问题
  • 原文地址:https://www.cnblogs.com/zhulijun/p/6652853.html
Copyright © 2011-2022 走看看