您现在的位置:首页 >> 前端 >> 内容

html04

时间:2016/12/17 9:31:00 点击:

  核心提示:!DOCTYPE htmlhtml lang=enheadmeta charset=UTF-8title/titlestyle.na{border: 1px solid red;}/style/hea...
<!DOCTYPE html>  
<html lang="en">  
<head>  
    <meta charset="UTF-8">  
    <title></title>  
    <style>  
        .na{  
            border: 1px solid red;  
        }  
    </style>  
</head>  
<body>  
    <p id="p1" style="width: 100px;height: 100px;background-color: #007bc5"  title=""></p>  
<script>  
    var op = document.getElementById("p1");  
    /*获取到p的所有属性,获取到属性跟元素设置的顺序相反*/  
    var attrArr = op.attributes;  
    for(var i=0;i<attrArr.length;i++){  
        console.info(attrArr[i]);  
    }  
  
    /*增加一个属性*/  
    op.setAttribute("name","test");  
    op.setAttribute("class","na");  
  
    /*删除属性*/  
    op.removeAttribute("title");  
  
    /*获取到指定的属性值*/  
    var str = op.getAttribute("style");  
    console.info(str);  
  
    /*op一定一个确定的标签元素*/  
    console.info(op.style);  
    op.style="width:200px;height:200px;background-color:red;";  
  
</script>  
</body>  
</html>

Tags:HT TM ML L0 
作者:网络 来源:qq_3586036
  • 上一篇:web配置
  • 下一篇:jquery文档