jQuery / Javascript - How do I convert a pixel value (20px) to a number value (20)

后端 未结 6 1744
北恋
北恋 2020-12-23 20:06

I know jQuery has a helper method for parsing unit strings into numbers. What is the jQuery method to do this?

var a = \"20px\";
var b = 20;
var c = $.parseM         


        
6条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-12-23 20:49

    $.parseMethod = function (s)
    {
        return Number(s.replace(/px$/, ''));
    };
    

    although how is this related to jQuery, I don't know

提交回复
热议问题