开发者

need code for counting from string

i want after i have been type 123A0001-123A0100 the result is 100. Or if 123A0123-123A0200 th开发者_如何学Ce result is 78. how do i do that?please help.

thanks before.


var str = 'A0001-A0100',
    match = str.match(/\d+/g);

if (match) {
    alert(+match[1] - +match[0]);
}

+ (unary plus) will cast the string to a number (does the same as Number(...)).


There is a calculation plug-in for jQuery.

Calculation plugin

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜