日期:2014-05-16 浏览次数:20457 次
$(".hh").css("fontSize", dd + "px");
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8"/>
<title>test</title>
<style type="text/css">
*{ margin:0; padding:0;}
body{font:12px/1.5 arial;background:#fff;}
</style>
<script type="text/javascript" src="../jquery-1.8.3.min.js"></script>
</head>
<body>
<div class="hh">adlkd</div>
<div id="font1">豪情壮志不言愁!</div>
<input type="text" name="" id="text01"><button id="btn0">设置大小</button> <br>
<button>12号字大小</button>
<button>14号字大小</button>
<button>16号字大小</button>
<script type="text/javascript">
function id(obj){
return document.getElementById(obj);
}
var text01 = id('text01'),
btnSet = id('btn0'),
font1 = id('font1');
btnSet.onclick = function(){
font1.style.fontSize = text01.value + 'px';
}
var arr = [0, 12, 14, 16],
btn = document.getElementsByTagName('button');
for(var i = 1; i < btn.length; i++){
btn[i].idx = i;
btn[i].onclick = function(){
font1.style.fontSize = arr[this.idx] + 'px';
console.log(i);
}
}
</script>
</body>
</html>
<style type="text/css">
#div1{ font-size:12px;}
</style>
<script src="http://code.jquery.com/jquery-latest.js"></script>