开发者

Splitting ID of element to return only the number

I have this line of code:

<a href="#" id="inv_1" class="load_invoice">

I am trying to use Javascript to spit back only the integer to be used for the rest of my control. What is the best method to do so?

Would .split be used or a simple regex开发者_如何学Go?


I usually use 'replace' for such things:

var myvar = 'inv_1';
myvar = myvar.replace('inv_','');
// myvar is now 1

http://www.w3schools.com/jsref/jsref_replace.asp

You can also use 'split':

var myvar = 'inv_1';
myvar = myvar.split('_');
// myvar[1] is now 1

http://www.w3schools.com/jsref/jsref_split.asp

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜