javascript怎么设置div边框

来自:互联网
时间:2021-06-30
阅读:

JavaScript设置div边框的步骤:

  • 获取div元素对象

  • 使用Style 对象的border属性来设置边框

border 属性在一个声明中设置所有边框属性。

语法:

Object.style.border=borderWidth borderStyle borderColor
描述
borderWidth 设置边框的宽度。
  • thin
  • medium
  • thick
  • length
borderStyle 设置边框的样式。
  • none
  • hidden
  • dotted
  • dashed
  • solid
  • double
  • groove
  • ridge
  • inset
  • outset
borderColor 设置边框的颜色。
  • color-name
  • color-rgb
  • color-hex
  • transparent

示例:

<!DOCTYPE html>
<html>
<head>
<style type="text/CSS">
div{ 
padding: 10px;
margin: 10px;
}
</style>
<script type="text/javascript">
function changeBorder()
{
document.getElementById("div1").style.border="thin dotted #FF0000";
}
</script>
</head>
<body>
<div id="div1">div元素,测试文本</div><br /><br />
<input type="button" onclick="changeBorder()" value="设置div边框" />
</body>
</html>

效果图:

javascript怎么设置div边框

返回顶部
顶部