DOCUMENT / 文档

HTML DOM Style border 属性

HTML DOM Style border 属性

Style border 属性

Style 对象

定义和用法

border 属性以速记形式设置或返回三个独立的边框属性。

通过该属性,您可以设置/返回:

  • border-width

  • border-style

  • border-color

语法

设置 border 属性:

Object.style.border="width style color"

返回 border 属性:

Object.style.border

提示:border 属性没有默认值。

参数描述
width设置边框的宽度。
style设置边框的样式。
color设置边框的颜色。

浏览器支持

Internet ExplorerFirefoxOperaGoogle ChromeSafari

所有主要浏览器都支持 border 属性。

实例

实例

更改 div 元素的边框:

<html>

<head>

<style type="text/css">

#ex1

{

border: thin dotted #FF0000;

}

</style>

<script>

function displayResult()

{

document.getElementById("ex1").style.border="thick solid #0000FF";

}

</script>

</head>

<body>


<div id="ex1">This is some text</div>

<br>

<button type="button" onclick="displayResult()">Change border</button>


</body>

</html>
尝试一下 »

Style 对象