jQuery——属相操作

属性获取:attr(属性名),

属性设置:attr(属性名,具体值)

移除属性:removeAttr(属性名)

特殊情况:prop(属性名)、prop(属性名,具体值);表单中状态属性checked、selected、disabled要使用.prop()方法

使用技巧:整体移除class属性,可以用removeAttr("class")

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script src="jquery-1.11.1.js"></script>
    <script>
        $(function () {
            $("button").eq(0).on("click", function () {
                $("input").prop("checked", true);

            });
            $("button").eq(1).on("click", function () {
                $("input").removeAttr("checked");
            });
        });

    </script>
</head>
<body>
<button>设置</button>
<button>移除</button>
<input type="radio"><div></div>
</body>
</html>
原文地址:https://www.cnblogs.com/wuqiuxue/p/8038508.html