In my code I split a string based on _
and grab the second item in the array.
var element = $(this).attr('class');
var field = element.split('_')[1];
Takes good_luck
and provides me with luck
. Works great!
But, now I have a class that looks like good_luck_buddy
. How do I get my javascript to ignore the second _
and give me luck_buddy
?
I found this var field = element.split(new char [] {'_'}, 2);
in a c# stackoverflow answer but it doesn't work. I tried it over at jsFiddle...
Question&Answers:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…