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

后端 未结 6 1729
北恋
北恋 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:40

    $(document).ready(function(){
    $("#btnW1").click(function(){
    $("#d1").animate({
    width: "+=" + x, }); });

    When trying to identify the variable x with a pixel value I by using jquery I put the += in quotes. Instead of having width: '+= x', which doesn't work because it thinks that x is a string rather than a number. Hopefully this helps.

提交回复
热议问题