12JavaScript Dom动态设置元素的float样式

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <title></title>
    <style type="text/css">
        div {
            width: 300px;
            height: 200px;
            background-color: Yellow;
        }
    </style>
    <script type="text/javascript">
        onload = function () {
            //操作float样式的时候,IE与其他浏览器不太一样。
            //IE:obj.style.styleFloat=‘right’;
            //其他浏览器:obj.style.cssFloat=‘right’;
            document.getElementById('btn').onclick = function () {
                var dvObj = document.getElementById('dv');
                if (typeof (dvObj.style.styleFloat) == 'string') {
                    //是IE
                    dvObj.style.styleFloat = 'right';
                } else {
                    //不是IE
                    dvObj.style.cssFloat = 'right';
                };
            };
        };

    </script>

</head>
<body>
    <input type="button" name="name" value="浮动" id="btn" />
    <div id="dv">
    </div>
</body>
</html>

  

posted on 2016-01-07 22:27  努力的活着_在人间  阅读(326)  评论(0)    收藏  举报

导航