首页 > 其他 > 详细

05-4-style的代替操作

时间:2019-09-06 19:39:07      阅读:99      评论:0      收藏:0      [点我收藏+]
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <style>
        #wrap.box{
            height: 150px;
            background-color: #999;
            border: 5px solid red;
        }
    </style>
</head>
<body>
<div id="wrap" style="width: 150px;"></div>
<script>
    let oWrap = document.getElementById(‘wrap‘);
    /*
    oWrap.style.height = ‘150px‘;
    oWrap.style.backgroundColor = ‘red‘;
    oWrap.style.border = ‘1px solid #999‘;
    */

    //行内样式表中的内容用cssText
    // console.log(oWrap.style.cssText);
    //这里可以使用+=添加,这是给属性加属性  和上边的3行是一样的 一次性操作多个样式
    // oWrap.style.cssText += ‘height:150px;background-color:red;border:1px solid #999‘;
    // console.log(oWrap.style.cssText);

    //加这些属性的时候需要考虑兼容  直接float是不可以的
    oWrap.style.cssFloat = ‘left‘;
    oWrap.style.styleFloat = ‘left‘;

    //终极操作多个style可以靠操作class名来实现
    oWrap.className = ‘box‘;
    //但是如果本身有class名字,需要加空格
    oWrap.className += ‘ goudan‘;
</script>
</body>
</html>

 

05-4-style的代替操作

原文:https://www.cnblogs.com/zhangyu666/p/11477726.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!