小码哥的IT人生

HTML DOM borderWidth 属性

JavaScript基础 2022-06-08 14:26:56小码哥的IT人生shichen

HTML DOM borderWidth 属性

定义和用法

borderWidth 属性设置所有四个边框的宽度。

该属性可使用 1 到 4 个值:

  1. 如果规定一个值,比如 div {border-width: thick} - 所有四个边框都是粗线。
  2. 如果规定两个值,比如 div {border-width: thick thin} - 上下边框是粗线,而左右边框是细线。
  3. 如果规定三个值,比如 div {border-width: thick thin medium}- 上边框是粗线,左右边框是细线,下边框是中等 (medium) 的宽度。
  4. 如果规定四个值,比如 div {border-width: thick thin medium 10px} - 上边框是粗线,右边框是细线,下边框是中等的宽度,而左边框是 10px 的宽度。

语法:

Object.style.borderWidth=thin|medium|thick|length

可能的值:

描述
thin 定义细的下边框。
medium 默认。定义中等的下边框。
thick 定义粗的下边框。
length 允许您自定义下边框的宽度。

实例

本例改变边框的宽度:

<html>
<head>
<style type="text/css">
p
{
border: thin solid #FF0000
}
</style>
<script type="text/javascript">
function changeBorderWidth()
{
document.getElementById("p1").style.borderWidth="thick thin";
}
</script>
</head>
<body>
<input type="button" onclick="changeBorderWidth()"
value="Change border widths" />
<p id="p1">This is a paragraph</p>
</body>
</html>

TIY

完整实例【borderWidth - 改变所有四个边框的宽度】:

<html>
<head>
<style type="text/css">
p
{
border: thin solid #FF0000
}
</style>
<script type="text/javascript">
function changeBorderWidth()
{
document.getElementById("p1").style.borderWidth="thick thin";
}
</script>
</head>
<body>
<input type="button" onclick="changeBorderWidth()" value="Change border widths" />
<p id="p1">This is a paragraph</p>
</body>
</html>

可以使用本站在线JavaScript测试工具测试上述代码运行效果:http://www.phpcodeweb.com/runjs.html

版权所有 © 小码哥的IT人生
Copyright © phpcodeweb All Rights Reserved
ICP备案号:苏ICP备17019232号-2  

苏公网安备 32030202000762号

© 2021-2024