zoukankan      html  css  js  c++  java
  • data-属性

    dataset

    1. 能设置,也能获取
      var dom = document.getElementById("box");
          dom.dataset.myAge = 22; 
          //myAge的到的驼峰写法会自动转化为连接符号[data-my-age]
          console.log(dom.dataset.myAge); //22
    
    1. 使用dataset设置的一定会有data-部分

    使用css设置为
    [data-my-age] { color: blue; }

    getAttribute/setAttribute

          dom.setAttribute("data-name","xin");
          dom.setAttribute("age",23);
          dom.setAttribute("dataName","xin");
          //[dataname="xin"]--驼峰自动转化为小写
          //[data-name="xin"]-[age="23"]-可以直接设置属性,可以没有data
          console.log(dom.getAttribute("data-my-age"))//22
          console.log(dom.getAttribute("dataMyAge"))//null
          console.log(dom.getAttribute("dataName"))//"xin"
          //会自动转化为小写,得到对应的属性
          //获得属性必须用-连接,用驼峰得不到数据
    

    有一定的兼容性问题,慎重使用

  • 相关阅读:
    lua学习之循环求一个数的阶乘
    lua元表学习
    ArrayList与List性能测试
    安卓开发线程
    安卓开发
    全局设置导航栏
    LinearLayout
    安卓布局ConstraintLayout
    安卓网络请求和图片加载
    安卓启动页面
  • 原文地址:https://www.cnblogs.com/selfxin/p/5420193.html
Copyright © 2011-2022 走看看