js字体大小
2014-10-09来源:易贤网

<script>

var tgs = new Array( 'div','td','tr');

var szs = new Array( 'xx-small','x-small','small','medium','large','x-large','xx-large' );

var startSz = 2;

function ts( trgt,inc ) {

if (!document.getElementById) return

var d = document,cEl = null,sz = startSz,i,j,cTags;

sz += inc;

if ( sz < 0 ) sz = 0;

if ( sz > 6 ) sz = 6;

startSz = sz;

if ( !( cEl = d.getElementById( trgt ) ) ) cEl = d.getElementsByTagName( trgt )[ 0 ];

cEl.style.fontSize = szs[ sz ];

for ( i = 0 ; i < tgs.length ; i++ ) {

cTags = cEl.getElementsByTagName( tgs[ i ] );

for ( j = 0 ; j < cTags.length ; j++ ) cTags[ j ].style.fontSize = szs[ sz ];

}

}

</script>

<style>

.tabfont{font-size:12px}

</style>

<body>

<a href="javascript:ts('body',1)">+ 放大字体</a> | <a

href="javascript:ts('body',-1)">+ 减小字体</a><br><br>

<b>Javascript:</b><br><br>

<table align=center><tr><td class=tabfont>

var tgs = new Array( 'div','td','tr');<br>

var szs = new Array( 'xx-small','x-small','small','medium','large','x-large','xx-large' );<br>

var startSz = 2;<br>

function ts( trgt,inc ) {<br>

if (!document.getElementById) return<br>

var d = document,cEl = null,sz = startSz,i,j,cTags;<br>

sz += inc;<br>

if ( sz < 0 ) sz = 0;<br>

if ( sz > 6 ) sz = 6;<br>

startSz = sz;<br>

if ( !( cEl = d.getElementById( trgt ) ) ) cEl = d.getElementsByTagName( trgt )[ 0 ];<br>

cEl.style.fontSize = szs[ sz ];<br>

for ( i = 0 ; i < tgs.length ; i++ ) {<br>

cTags = cEl.getElementsByTagName( tgs[ i ] );<br>

for ( j = 0 ; j < cTags.length ; j++ ) cTags[ j ].style.fontSize = szs[ sz ];<br>

}<br>

}<br>

</td></tr>

</table>

</body>

更多信息请查看IT技术专栏

2025公考·省考培训课程试听预约报名

  • 报班类型
  • 姓名
  • 手机号
  • 验证码
推荐信息