js改变增加减小字号大小

<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title></title>
		<script type="text/javascript">
			window.onload = function(){
				
				var bts = document.getElementById('btns');
				var btx = document.getElementById('btnx');
				var txt = document.getElementById('txt');
				// console.log(txt.innerHTML);
				var sz = 16;
				bts.onclick = function(){
					sz = sz + 1;
					console.log(sz);
					txt.style.fontSize = sz + 'px';
				}
				btx.onclick = function(){
					sz = sz - 1;
					console.log(sz);
					txt.style.fontSize = sz + 'px';
				}
				
			}
		</script>
	</head>
	<body>
		<button type="button" id="btns">字号加</button>
		<button type="button" id="btnx">字号减</button>
		<p id="txt">中华人民共和国万岁!</p>
	</body>
</html>

 

posted @ 2022-02-25 16:51  JackieDYH  阅读(14)  评论(0编辑  收藏  举报  来源