2009-09-07 3 views
0

글꼴 크기를 늘리거나 줄이기위한 다음 스크립트를 찾았지만 누구나 기본 글꼴 기능을 수행하는 방법을 알고 있습니까?기본 텍스트 크기 기능을 추가하는 방법 - Javascript

var min=8; 
var max=18; 
function increaseFontSize() { 
    var p = document.getElementsByTagName('div'); 
    for(i=0;i<p.length;i++) { 
     if(p[i].style.fontSize) { 
     var s = parseInt(p[i].style.fontSize.replace("px","")); 
     } else { 
     var s = 12; 
     } 
     if(s!=max) { 
     s += 1; 
     } 
     p[i].style.fontSize = s+"px" 
    } 
} 
function decreaseFontSize() { 
    var p = document.getElementsByTagName('div'); 
    for(i=0;i<p.length;i++) { 
     if(p[i].style.fontSize) { 
     var s = parseInt(p[i].style.fontSize.replace("px","")); 
     } else { 
     var s = 12; 
     } 
     if(s!=min) { 
     s -= 1; 
     } 
     p[i].style.fontSize = s+"px" 
    } 
} 
+0

이 질문에 대한 답변을 제공해 주시겠습니까? – Aziz

+0

세 개의 버튼, 증가, 감소 및 기본 글꼴 크기가 있습니다. – Caremy

+0

A+ Caremy

답변

2
function resetToDefaultFontSize() { 
    var p = document.getElementsByTagName('div'); 
    for(i=0;i<p.length;i++) { 
     p[i].style.fontSize = "12px"; 
    } 
} 

참고 : 당신이 그것을 조사 할 수 있도록 jQuery를, 3 일 - 라이너로 이러한 모든 기능을 만들 수 있습니다.

www.jquery.com

+0

이 테스트를 거쳤습니다. 잘 작동합니다. 빠른 응답을 주셔서 감사합니다 iftrue Logged – Caremy

관련 문제