zoukankan      html  css  js  c++  java
  • juqery对象和dom对象 设置标签属性

    juqery对象和dom对象 对标签属性的操作

    代码

    
    
    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <title>Document</title>
        <script src="https://cdn.bootcss.com/jquery/3.4.1/jquery.js"></script>
    </head>
    <body>
       <ul>
           <li title="title1" value="1">aaaaa<span>1</span></li>
           <li title="title2" value="2">bbbbb<span>2</span></li>
           <li title="title3" value="3">ccccc<span>3</span></li>
           <li title="title4" value="4">ddddd<span>4</span></li>
       </ul> 
    </body>
    <script>
    $('li').click(function(e) {
        console.log("dom对象",e.currentTarget);
        console.log("jquery对象",$(e.currentTarget));
        console.log("$(e.currentTarget).children('span').text()",$(e.currentTarget).children("span").text());
        console.log("jquery对象获取属性值",$(e.currentTarget).attr('title'));
        console.log("dom对象获取属性值",e.currentTarget.title);
    })
    </script>
    </html>
    
    

    控制台效果

  • 相关阅读:
    复制文字时自动加版权
    Linux安装Docker
    ThreadLocal 理解
    Spring多数据源动态切换
    [LOJ#500]「LibreOJ β Round」ZQC的拼图
    [JLOI2015]装备购买
    「雅礼集训 2017 Day4」洗衣服
    [BJWC2011]元素
    [51nod1577]异或凑数
    [ARC101B]Median of Medians
  • 原文地址:https://www.cnblogs.com/panghu123/p/15176739.html
Copyright © 2011-2022 走看看