jquery属性操作

<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8" />
        <meta name="viewport" content="width=device-width, initial-scale=1">
        <title></title>
        <script src="jquery-3.5.1.min.js" type="text/javascript" charset="utf-8"></script>
        <script type="text/javascript">
            $(document).ready(function() {
                var jqBtn = $("button");
                var jqIpt = $("input");
                var jqCkb = $("input:checkbox");

                jqBtn.click(function() {
                    jqIpt.attr("abc", "furong");
                    console.log(jqIpt.attr("abc"));

                    jqIpt.attr("class", "quange");

                    // jqCkb.attr("checked", true); // 一次性的
                    jqCkb.prop("checked", true);
                });
            });
        </script>
    </head>
    <body>
        <button type="button">button</button>
        <input type="" name="" id="" value="" />
        <input type="checkbox" name="" id="" value="" />
    </body>
</html>

image

image

posted @ 2020-10-21 19:52  thomas_blog  阅读(125)  评论(0编辑  收藏  举报