从样式属性获取字体大小属性

问题描述 投票:1回答:2

我有一组段落元素

<p style="font-family:Tahoma; font-size:10.666666666666666; margin:0 0 0 0;">
<p style="font-family:Tahoma; font-size:10.666666666666666; margin:0 0 0 0;">
<p style="font-family:Tahoma; font-size:10.666666666666666; margin:0 0 0 0;">
<p style="font-family:Tahoma; font-size:10.666666666666666; margin:0 0 0 0;">

我必须在字体大小度之后写px。我无法使用我当前的代码

loop
$(this).css("font-size") 

我无法使用它,因为它显示了父级div的字体大小>

我有一组段落元素

jquery font-size
2个回答
3
投票

[有两种显而易见的方法,第一种方法是查看style属性,以搜索font-size:字符串后的数字,并用其自身替换该字符串,尽管在其中添加px


1
投票

这将读取当前值,在其后附加“ px”,然后将其重新分配。


0
投票
var fontSize = $('p').attr('style').match(/font-size:\s*(.*?);/)[1];
© www.soinside.com 2019 - 2024. All rights reserved.