jquery:元素的特性,属性和数据

特性

特性:attributes:值为string

属性

属性:properties:值为string、boolean、number、object;

区分

属性能获取值,特性获取不了

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <script src="../Jquery/jquery-3.3.1/jquery-3.3.1.js"></script>
    <script src="../Jquery/jquery-3.3.1/jquery-3.3.1.min.js"></script>
</head>
<body>
    <img id="logo" src="https://ss3.bdstatic.com/70cFv8Sh_Q1YnxGkpoWK1HF6hhy/it/u=3142343904,631493091&fm=26&gp=0.jpg" title="CSDN logo" alt="Jquery logo" class="img-jquery" >

    <input type="checkbox" id="check" tabindex="1" style="width: 50px; height: 50px;" 
    title="Check this!" description ="just a checkbox" />
    <script>
    $(function () {
        function byid(id) {
            return typeof(id) === "string" ?document.getElementById(id) : id;
        }
        //var img =document.getElementById("logo");

        // 打印img特性
        //console.log(img.attributes);

        // 获取img的class的特性的值 (特性的值都是字符串)
        //console.log(img.getAttribute('class'));


        var checkbox = byid("check");
        //打印icheckbox.tabindex特性
        console.log(checkbox.getAttribute("tabindex"));
        // 获取属性值(与楼上颜色不一样)
        console.log(checkbox.tabIndex);
        // 返回值
        console.log(checkbox.getAttribute('style'));
        // 返回对象,对象里包t含所有属性
        console.log(checkbox.style);
       
        
    })
    
    </script>
</body>
</html>

在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值