DIV CSS 佈局教程網

 DIV+CSS佈局教程網 >> 網頁腳本 >> JavaScript入門知識 >> JavaScript綜合知識 >> 控制字體大小JS代碼
控制字體大小JS代碼
編輯:JavaScript綜合知識     

 

  <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>
<p><a href="http:///edu" target="_blank">教程</a></p>
</body>
XML學習教程| jQuery入門知識| AJAX入門| Dreamweaver教程| Fireworks入門知識| SEO技巧| SEO優化集錦|
Copyright © DIV+CSS佈局教程網 All Rights Reserved