js对按钮添加css样式

firefox等可以使用
var dom=document.getElementById("name");
dom.setAttribute("style","width:10px;height:10px;border:solid 1px red;") ;


IE中则必须使用style.cssText
var dom=document.getElementById("name");
dom1.style.cssText = "width:10px;height:10px;border:solid 1px red;";
补充一下,目前style.cssText类似innerHTML了,已经成为一个web开发的事实标准。因此测试显示firefox浏览器也支持这种方式。

另附按钮的几个CSS样式:

<style type="text/css">
.btn
{
border-right: #7b9ebd 1px solid;
padding-right: 2px;
border-top: #7b9ebd 1px solid;
padding-left: 2px;
font-size: 12px;
filter: progid:DXImageTransform.Microsoft.Gradient(GradientType=0, StartColorStr=#ffffff, EndColorStr=#cecfde);
border-left: #7b9ebd 1px solid;
cursor: hand;
color: black;
padding-top: 2px;
border-bottom: #7b9ebd 1px solid;
}
.btn1_mouseout
{
border-right: #7EBF4F 1px solid;
padding-right: 2px;
border-top: #7EBF4F 1px solid;
padding-left: 2px;
font-size: 12px;
filter: progid:DXImageTransform.Microsoft.Gradient(GradientType=0, StartColorStr=#ffffff, EndColorStr=#B3D997);
border-left: #7EBF4F 1px solid;
cursor: hand;
color: black;
padding-top: 2px;
border-bottom: #7EBF4F 1px solid;
}
.btn1_mouseover
{
border-right: #7EBF4F 1px solid;
padding-right: 2px;
border-top: #7EBF4F 1px solid;
padding-left: 2px;
font-size: 12px;
filter: progid:DXImageTransform.Microsoft.Gradient(GradientType=0, StartColorStr=#ffffff, EndColorStr=#CAE4B6);
border-left: #7EBF4F 1px solid;
cursor: hand;
color: black;
padding-top: 2px;
border-bottom: #7EBF4F 1px solid;
}
.btn2
{
padding: 2 4 0 4;
font-size: 12px;
height: 23;
background-color: #ece9d8;
border-width: 1;
}
.btn3_mouseout
{
border-right: #2C59AA 1px solid;
padding-right: 2px;
border-top: #2C59AA 1px solid;
padding-left: 2px;
font-size: 12px;
filter: progid:DXImageTransform.Microsoft.Gradient(GradientType=0, StartColorStr=#ffffff, EndColorStr=#C3DAF5);
border-left: #2C59AA 1px solid;
cursor: hand;
color: black;
padding-top: 2px;
border-bottom: #2C59AA 1px solid;
}
.btn3_mouseover
{
border-right: #2C59AA 1px solid;
padding-right: 2px;
border-top: #2C59AA 1px solid;
padding-left: 2px;
font-size: 12px;
filter: progid:DXImageTransform.Microsoft.Gradient(GradientType=0, StartColorStr=#ffffff, EndColorStr=#D7E7FA);
border-left: #2C59AA 1px solid;
cursor: hand;
color: black;
padding-top: 2px;
border-bottom: #2C59AA 1px solid;
}
.btn3_mousedown
{
border-right: #FFE400 1px solid;
padding-right: 2px;
border-top: #FFE400 1px solid;
padding-left: 2px;
font-size: 12px;
filter: progid:DXImageTransform.Microsoft.Gradient(GradientType=0, StartColorStr=#ffffff, EndColorStr=#C3DAF5);
border-left: #FFE400 1px solid;
cursor: hand;
color: black;
padding-top: 2px;
border-bottom: #FFE400 1px solid;
}
.btn3_mouseup
{
border-right: #2C59AA 1px solid;
padding-right: 2px;
border-top: #2C59AA 1px solid;
padding-left: 2px;
font-size: 12px;
filter: progid:DXImageTransform.Microsoft.Gradient(GradientType=0, StartColorStr=#ffffff, EndColorStr=#C3DAF5);
border-left: #2C59AA 1px solid;
cursor: hand;
color: black;
padding-top: 2px;
border-bottom: #2C59AA 1px solid;
}
.btn_2k3
{
border-right: #002D96 1px solid;
padding-right: 2px;
border-top: #002D96 1px solid;
padding-left: 2px;
font-size: 12px;
filter: progid:DXImageTransform.Microsoft.Gradient(GradientType=0, StartColorStr=#FFFFFF, EndColorStr=#9DBCEA);
border-left: #002D96 1px solid;
cursor: hand;
color: black;
padding-top: 2px;
border-bottom: #002D96 1px solid;
}
</style>

<form id="form1" runat="server">
<div>
<p>
<button class="btn" title="CSS样式按钮">
CSS样式按钮</button></p>
<p>
<button class="btn1_mouseout" onmouseover="this.className='btn1_mouseover'" onmouseout="this.className='btn1_mouseout'"
title="CSS样式按钮">
CSS样式按钮</button></p>
<p>
<button class="btn1_mouseout" onmouseover="this.className='btn1_mouseover'" onmouseout="this.className='btn1_mouseout'"
disabled>
CSS样式按钮</button></p>
<p>
<button class="btn2" title="CSS样式按钮">
CSS样式按钮</button></p>
<p>
<button class="btn3_mouseout" onmouseover="this.className='btn3_mouseover'" onmouseout="this.className='btn3_mouseout'"
onmousedown="this.className='btn3_mousedown'" onmouseup="this.className='btn3_mouseup'"
title="CSS样式按钮">
CSS样式按钮</button></p>
<p>
<button class="btn_2k3" title="CSS样式按钮">
CSS样式按钮</button></p>
</div>
</form>

你可能感兴趣的:(css,浏览器,Microsoft,IE,firefox)