zoukankan      html  css  js  c++  java
  • DOM 之 document 查找元素方法

    DOM 之 document 查找元素方法
    getElementById("idName"); // 始终取得第一个 idName 的元素

    getElementsByTagName("元素标签名") // 返回是一个集合,可用[索引值]来获取相关指定元素或者通过 item(索引值),如

    getElementsByTagName("p")[0] / getElementsByTagName

    ("p").item(1);

    getElementsByName("name"); // 也就是说元素必须带有 name 属性才可以获取,也是一个数组,如 <input type="text" name="name" />

    ===================
    文档写入
    write()/writeln()
    document.write("内容"); / document.writeln("内容");

    ===============
    取得特性
    getAttribute()

    // getAttribute() 用法
    var div = document.getElementById("myDiv");
    alert(div.getAttribute("id"));
    alert(div.getAttribute("class"));
    alert(div.getAttribute("title"));

    ==================

    取得特性
    setAttribute()

    // setAttribute() 用法
    var div = document.getElementById("myDiv");
    alert(div.setAttribute()("id", "myid"));
    alert(div.setAttribute()()("class", "myClass"));
    alert(div.setAttribute()("title", "myTitle"));

    ============

    移除特性
    removeAttribute()

    // removeAttribute() 用法
    var div = document.getElementById("myDiv");
    alert(div.removeAttribute("id"));
    alert(div.removeAttribute("class"));
    alert(div.removeAttribute("title"));

  • 相关阅读:
    视频分解图片,图片合成视频
    获取图片中指定区域图片
    CALayer alpha mask not working
    多媒体编程ios摄像头图像抓取工具类
    10月17日
    10月16日
    10月15日
    10月14日
    10月13日
    10月12日
  • 原文地址:https://www.cnblogs.com/lin3615/p/3648768.html
Copyright © 2011-2022 走看看