js 修改边框颜色

JavaScript050

js 修改边框颜色,第1张

不要混合html属性和css属性(测试发现似乎只有IE会这样)。

在table里添加属性style="border-color:#00F",然后去掉bordercolor属性:

<script type="text/javascript">

function borderit(which){

//if IE 4+ or NS 6+

if (document.all||document.getElementById){

which.style.borderColor="FF0000"

}

}

</script>

</head>

<table border="3" onmousemove="borderit(this)" style="border-color:#00F" cellpadding="0" cellspacing="0">

<tr><td>2345345345</td></tr>

</table>

我的做法是:

假如你所说的那段文字放在一个DIV里,DIV的class属性就是定义DIV容器里的元素的样式的,id就是给javascript获取到该元素的。获取到之后通过改class属性,就相当于改了div里的样式

<html>

<head>

<style type="text/css">

.style1{font-size:12pxfont-weight:blodcolor:red}

.style2{font-size:14pxfont-weight:blodcolor:blue}

</style>

<script language="javascript" type="text/javascript">

function change(){

document.getElementById("myword").className= "style2"

}

</script>

</head>

<body>

<div><a href="#" class="style1" id="myword" onclick="change()">我是DIV里的文字</a></div>

</body>

</html>