文字放大縮小
阿新 • • 發佈:2017-05-18
log style 代碼 -s 增加 image har code fonts
1.點擊減小按鈕,文字變小
2.點擊增加按鈕,文字變大
1 <!DOCTYPE HTML> 2 <html> 3 <head> 4 <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> 5 <title>無標題文檔</title> 6 <script> 7 window.onload = function (){ 8 var oBtn1 = document.getElementById(‘btn1‘);示例代碼:9 var oBtn2 = document.getElementById(‘btn2‘); 10 var oP = document.getElementById(‘p1‘); 11 var num = 14; 12 13 oBtn1.onclick = function (){ 14 num -= 2; 15 oP.style.fontSize = num + ‘px‘; 16 // JS 不允許出現"-" 17 // padding-top paddingTop 18 //margin-left marginLeft 19 }; 20 oBtn2.onclick = function (){ 21 // num = num + 2; 22 num += 2; 23 24 oP.style.fontSize = num + ‘px‘; 25 // JS 不允許出現“-“ 26 }; 27 }; 28 </script> 29 </head> 30 31 <body> 32 33 <input id="btn1" type="button" value="-" /> 34<input id="btn2" type="button" value="+" /> 35 <p id="p1" style="font-size:16px;">10月28日晚,中央紀委監察部官網發布消息,貴州省委常委、遵義市委書記廖少華因涉嫌嚴重違紀違法接受組織調查。3天後中組部宣布對其免職。廖成為十八大後中紀委一連串"打虎"行動中第十一位落馬的副省部級以上高官。</p> 36 37 </body> 38 </html>
文字放大縮小