Add javascript pixel values?

前端 未结 5 482
甜味超标
甜味超标 2021-02-05 14:45

Is there a way in javascript/jQuery to take two variables with values \"60px\" and \"40px\" and add them together to get \"100px\"?

Or in a more general sense, I\'m tryi

5条回答
  •  野的像风
    2021-02-05 15:30

    remove px from strings, add values, then add px back

      (parseInt("40px".replace(/px/,""))+60)+"px"
    

提交回复
热议问题