用 jQuery 删除第一个字符
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/16704732/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Remove first character with jQuery
提问by sephiith
How would I go about removing the first character from this.className in the below line? The first variable will be _ and then a number. I just want the number to be assigned to className.
我将如何从下一行中的 this.className 中删除第一个字符?第一个变量将是 _,然后是一个数字。我只想将数字分配给 className。
className = this.className;
Furthermore I am changing "$('.inter').html(window[link[className]]);"
to use an array instead of the className variable. Is the below code the correct way to use an array with the index as a variable?
此外,我正在更改"$('.inter').html(window[link[className]]);"
使用数组而不是 className 变量。下面的代码是使用索引作为变量的数组的正确方法吗?
$('.inter').html(window[link[className]]);
回答by Benjamin Gruenbaum
No need to use jQuery for that, just plain ol' javascript using .substring
无需为此使用 jQuery,只需使用简单的 ol' javascript .substring
var trimmed = this.className.substring(1);