在jQuery中设置字体大小 [英] set font size in jquery

查看:137
本文介绍了在jQuery中设置字体大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我无法使用Jquery更改字体大小.我想更改div的字体大小.我已将主体的默认字体大小定义为12.我尝试如下进行更改,但是它没有用:(

I'm not able to change font size using Jquery. I want to change font size of a div. I have defined default font size for body as 12. I tried to change it as follows, but it didn't work :(

$("#SelFontSize").change(function(){
$("#"+styleTarget).css({'font-size':'"+$(this).val()+"px'});    
});

推荐答案

尝试:

$("#"+styleTarget).css({ 'font-size': $(this).val() });

通过将值放在引号中,它变为字符串,并且"+$(this).val()+"px绝对不接近字体值.设置元素的样式属性有两种方法:

By putting the value in quotes, it becomes a string, and "+$(this).val()+"px is definitely not close to a font value. There are a couple of ways of setting the style properties of an element:

使用地图:

$("#elem").css({
    fontSize: 20
});

使用键和值参数:

所有这些都是有效的.

$("#elem").css("fontSize", 20);
$("#elem").css("fontSize", "20px");
$("#elem").css("font-size", "20");
$("#elem").css("font-size", "20px");

您可以将"fontSize"替换为"font-size",但必须在其后加上引号.

You can replace "fontSize" with "font-size" but it will have to be quoted then.

这篇关于在jQuery中设置字体大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆