js中设置div边框高度

JavaScript018

js中设置div边框高度,第1张

设置div边框高度,其实就是设置div的高度,修改css样式可以实现

元素.style.height = '10px'//将高度设为10px

元素.style.width = '20px'//将宽度设为20px

举个例子:

<!doctype html>

<html lang="en">

<head>

    <meta charset="UTF-8">

    <style>

        div{

            height: 100px

            width: 100px

            background-color: #3e6bb8

        }

    </style>

</head>

<body>

<div></div>

<script>

    var mdiv = document.getElementsByTagName('div')[0]//获得元素

    mdiv.style.height = '200px'//设高为200,变成一个100 * 200 的长方形

    mdiv.style.width = '200px'//设宽为200,变成一个200 * 200 的正方形

</script>

</body>

</html>

你的代码写的不规范,属性的值需要加引号obj.style.border=0px 这个地方 opx是字符串 也需要引号的 obj.style.border=0或obj.style.border=‘0px’ 都可以 下面是一个正常的例子 有用的话 选我为满意答案 谢谢。<!DOCTYPE html><html> <head> <meta charset="utf-8" /> <title>border</title> <style type="text/css"> div.one{border:1px solid #000000background:#fff}</style> <script type="text/javascript"> function removes(){divs = document.getElementsByTagName("div") alert(""+divs.length+"") for (i = 0i <divs.length i++){ remove(divs[i]) }}function remove(obj){obj.style.border = '0px' }</script> </head> <body> <div class="one" id="dragdiv1"> <textarea id="1">1</textarea> </div> <div class="one" id="dragdiv2"> <textarea id="2">2</textarea> </div> <div class="one" id="dragdiv3"> <textarea id="3">3</textarea> </div> <button onclick="removes()">去div边框</button> </body></html>