欢迎您访问新疆栾骏商贸有限公司,公司主营电子五金轴承产品批发业务!
全国咨询热线: 400-8878-609

新闻资讯

常见问题

使用JavaScript动态设置样式实现代码(2)

作者:用户投稿2026-01-11 13:08:41
你可以参考到前一版本 https://www./article/33555.htm 这个有点不好的地方,就是如果想改变样式,也许得使用查找替换才行。

因此,Insus.NET写出另外一个方法来实现,这样可以改一应用百。
先写一个样式Style:
复制代码 代码如下:
<style type="text/css">
.overStyle
{
border-color:#3599ff;
}
.outStyle
{
border-color: #fff;
}
</style>

Javascript也要改一下:
复制代码 代码如下:
<script type="text/javascript">
function onOver(Id) {
Id.className = 'overStyle';
}
function onOut(Id) {
Id.className = 'outStyle';
}
</script>

最后是html的动态应用。
复制代码 代码如下:
<fieldset id="fs1" style="margin: 10px; padding: 10px; width: 170px; text-align: center;"
onmouseover="onOver(this)" onmouseout="onOut(this)">
ERP <a href="http://xxx.xxx.com/erp" target="_blank">http://xxx.xxx.com/erp </a>
</fieldset>