<!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">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>JQuery css函数测试</title>
<script src="jquery-1.2.6.js" type="text/javascript"></script> //导入jquery
<script type="text/javascript">
$(document).ready(function(){
$('div .button' ).click(function(){ //注意之间有空格代表div 下有class为button的
var $duanluo=$('div.speech' ); //jQuery 变量 存储段落信息 div.speech注意之间没有空格 当然.speech也行
var ziti=$duanluo.css('fontSize'); //字体信息 大小 如:8px
//alert(ziti);测试结果ziti是 8 px
var ztdx=parseFloat(ziti,10) ; //取以字母开头的字符串为 10 (第二个参数) 进制数字
//alert(ztdx);
var unit= ziti.slice(-2); //取字体信息的 单位 如:8px 中的px slice取字符串 从倒数第二个开始取
if (this.id=='switcher-large'){ztdx *= 1.4;}
else if (this.id=='switcher-small'){ztdx/= 1.4;}
$duanluo.css('fontSize', ztdx + unit); //段落的css应用处理后的字体大小
});
});
</script>
</head>
<body>
<center><h1>JQuery css函数测试</h1></center>
<div id="switcher">
<spent class"label"> Stryle Switcher:</spent><br> //spent默认在同一行上所以用 <br>
<spent class ="button" id ="switcher-large" > + 加大 + </spent><br> //用<div也行>
<spent class ="button" id ="switcher-small" > - 减小 - </spent>
</div>
<div class ="speech" >
<p>
<b>jQuery是一个了不起的javascript库,它可以是我们用很少的几句代码就可以创建出漂亮的页面效果。</b>
</p>
</div>
</body>
</html>