jQuery之字体⼤⼩的设置
先获取字体⼤⼩,进⾏处理。
再将修改的值保存。
slice() ⽅法可从已有的数组中返回选定的元素。
arrayObject.slice(start,end)。
start    必需。规定从何处开始选取。如果是负数,那么它规定从数组尾部开始算起的位置。也就是说,-1 指最后⼀个元素,-2 指倒数第⼆个元素,以此类推。
end    可选。规定从何处结束选取。该参数是数组⽚断结束处的数组下标。如果没有指定该参数,那么切分的数组包含从 start 到数组结束的所有元素。如果这个参数是负数,那么它规定的是从数组尾部开始算起的元素。
jQuery代码如下:
<script type="text/javascript">
$(function(){
$("span").click(function(){
//获取para的字体⼤⼩
var thisEle = $("#para").css("font-size");
//parseFloat的第⼆个参数表⽰转化的进制,10就表⽰转为10进制
var textFontSize = parseFloat(thisEle , 10);
//javascript⾃带⽅法
var unit = thisEle.slice(-2); //获取单位
var cName = $(this).attr("class");
if(cName == "bigger"){
textFontSize += 2;
}else if(cName == "smaller"){
textFontSize -= 2;
}
//设置para的字体⼤⼩
$("#para").css("font-size",  textFontSize + unit );
});
});
</script>
jquery 字符串转数组
html代码如下:
<body>
<div class="msg">
<div class="msg_caption">
<span class="bigger" >放⼤</span>
<span class="smaller" >缩⼩</span>
</div>
<div>
<p id="para" >
This is some text. This is some text. This is some text. This is some text. This
is some text. This is some text. This is some text. This is some text. This is some
text. This is some text. This is some text. This is some text. This is some text.
This is some text. This is some text. This is some text. This is some text. This
is some text. This is some text.
</p>
</div>
</div>
</body>

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。