zoukankan      html  css  js  c++  java
  • 妙味——操作元素属性的几种方法

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
    <head>
    <meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
    <title>Document</title>
    <script>
    window.onload=function(){
        var oTxt = document.getElementById('txt');
    
        // 操作元素属性的几种方法:
        // 1、        .
        // oTxt.value='123';
    
        // 2、        [],优点是里面元素可变
        // oTxt['value']='123';
    
        //3、        DOM方法
        oTxt.setAttribute('value','123');
    
        // setAttribute是设置属性的方法
        // getAttribute是获取属性的方法
        // removeAttribute是删除属性的方法
    }
    </script>
    </head>
    <body>
        <input type="text" name="" id="txt" />
    </body>
    </html>

    其中:

    setAttribute(名称,值)
    getAttribute(名称)
    removeAttribute(名称)
    
    
    高否?富否?帅否? 否? 滚去学习!
  • 相关阅读:
    C# 设计模式
    FutureTask、Fork/Join、 BlockingQueue
    线程的几种创建方式
    行锁、表锁、乐观锁、悲观锁
    J.U.C之AQS
    同步容器并发容器
    线程不安全类
    线程封闭
    不可变对象
    安全发布对象—单例模式
  • 原文地址:https://www.cnblogs.com/baixc/p/3458375.html
Copyright © 2011-2022 走看看