jQuery操作DOM基础 - 元素属性的查看与设置

 

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script type="text/javascript" src="jquery-3.1.0.js"></script>
    <script type="text/javascript">
        $(function(){
            $("input[type='button']").click(function(){
                alert("文本框内容:"+$("input:first").attr("type"));
                alert("文本框内容:"+$("input:first").attr("placeholder"));
                $("input:first").attr("value","张柳宁");
            })
        })
    </script>
</head>
<body>
    <input type="text" placeholder="输入内容"/>
    <input type="button" value="按钮"/>
</body>
</html>

使用jQuery对象的attr()函数实现元素属性的获取的设置

 

posted @ 2016-07-28 21:50  csnmd  阅读(238)  评论(0编辑  收藏  举报