日期:2014-05-16 浏览次数:20375 次
var x = $("test"); var y = x.getElementsByTagName("input"); for (var i = 0;i < y.length; i++) { if(y[i].className == "aa") { y[i].className = "bb"; } }
------解决方案--------------------
<style type="text/css"> .aa { width:20px; } </style> <input name="a1" class="aa" type="text" /><br /> <input name="b2" class="aa" type="text" /><br /> <input name="c3" class="aa" type="text" /><br /> <input type="button" value="确定" onclick="aa();" /> <script language="javascript" type="text/javascript"> function aa() { var styleSheets = document.styleSheets; var rules = styleSheets[0].rules; for (var i=0;i<rules.length;i++) { if (rules[i].selectorText == ".aa") { rules[i].style.width = "200px"; } } } </script>
------解决方案--------------------
用于firefox
<style type="text/css">
.aa
{
width:20px;
}
</style>
<input name="a1" class="aa" type="text" /><br />
<input name="b2" class="aa" type="text" /><br />
<input name="c3" class="aa" type="text" /><br />
<input type="button" value="确定" onclick="aa();" />
<script language="javascript" type="text/javascript">
function aa()
{
var styleSheets = document.styleSheets;
var cssRules = styleSheets[0].cssRules;
for (var i=0;i<cssRules.length;i++)
{
if (cssRules[i].selectorText == ".aa")
{
cssRules[i].style.width = "200px";
}
}
}
</script>