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
精彩评论