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
.(注意到good_luck
并为我提供了luck
。) Works great!(很棒!)
But, now I have a class that looks like good_luck_buddy
.(但是,现在我有一个看起来像good_luck_buddy
的类。) How do I get my javascript to ignore the second _
and give me luck_buddy
?(如何获取我的JavaScript来忽略第二个_
并给我luck_buddy
?)
I found this var field = element.split(new char [] {'_'}, 2);
(我发现这个var field = element.split(new char [] {'_'}, 2);
) in ac# stackoverflow answer but it doesn't work.(在ac#stackoverflow答案中,但不起作用。) I tried it over at jsFiddle...(我在jsFiddle上尝试过...)
ask by Ofeargall translate from so
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…