//var tgs = new Array('div','td','tr'); var tgs = new Array('td','tr'); //Specify spectrum of different font sizes: //var szs = new Array( 'xx-small','x-small','small','medium','large','x-large','xx-large' ); var szs = new Array( '10px','12px','14px','16px','18px','20px','22px' ); var startSz = 2; function tsize( trgt,inc ) { if (!document.getElementById) { return } var d = document,cEl = null,sz = startSz,i,j,cTags; //sz += inc; 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 ]; } } }
使用方法:
<td> <a href="javascript:tsize('body',0)"> <img src="https://www.jb51.net/image/fsize1of.gif"></a> </td>
更多关于JavaScript相关内容感兴趣的读者可查看本站专题:《JavaScript切换特效与技巧总结》、《JavaScript查找算法技巧总结》、《JavaScript动画特效与技巧汇总》、《JavaScript错误与调试技巧总结》、《JavaScript数据结构与算法技巧总结》、《JavaScript遍历算法与技巧总结》及《JavaScript数学运算用法总结》