[英]extracting and pasting a part of string using javascript
I have people inputting 125px and 125% I want to extract just 125 from this perform some calulation on it. 我要输入125px和125%的人,我想从中提取125px,然后对它进行一些计算。 125 * 2 Then I want to add px or % as it was set before 250px and 250%
125 * 2然后,我想添加250px和250%之前设置的px或%
I'm guessing something like this should work: 我猜像这样的事情应该工作:
//str is equal to your string
var num = str.substring(0,str.search(/[^0-9]/))/1;
var sub = str.substring(str.search(/[^0-9]/));
num=num*2;
var newstr = num+sub;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.