我需要做一个基于CSS属性的数值计算.然而,当我用这个来获取信息时:
$(this).css('marginBottom')
它返回值"10px".不管是px
、%
、em
还是其他值,只获取数值的数字部分有什么诀窍吗?
我需要做一个基于CSS属性的数值计算.然而,当我用这个来获取信息时:
$(this).css('marginBottom')
它返回值"10px".不管是px
、%
、em
还是其他值,只获取数值的数字部分有什么诀窍吗?
This will clean up all non-digits, non-dots, and not-minus-sign from the string:
$(this).css('marginBottom').replace(/[^-\d\.]/g, '');
已针对负值更新