Javascript 如何删除 JQuery 中的前 3 个字母?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/8268052/
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
How to remove first 3 letters in JQuery?
提问by Jacob
How can I remove the first three letters of a string in JQuery?
如何在 JQuery 中删除字符串的前三个字母?
For example: Turn cat1234
to 1234
例如:打开cat1234
到1234
回答by jAndy
No jQuery needed.
不需要jQuery。
"cat1234".slice(3);
or
或者
"cat1234".substring(3);
or
或者
"cat1234".substr(3);
var str="cat1234";
console.log("using slice =",str.slice(3));
console.log("using substring =",str.substring(3));
console.log("using substr =",str.substr(3));
回答by Jwalin Shah
var val = 'cat1234';
var newVal = val.substring(3, val.length);
回答by Abdul Munim
You don't need jQuery to do this, JavaScript will do:
你不需要 jQuery 来做到这一点,JavaScript 会做到:
"cat1235".substring(3) // yields 1235
回答by WTK
How about vanilla javascript:
香草javascript怎么样:
'cat1234'.slice(3)
# returns '1234'
回答by Martin.
回答by jenson-button-event
function trimCat() { return "cat1234".substring(3, 6); }
or
或者
function trimAnotherCat() { return "cat1234".replace("cat", ""); }
回答by martincarlin87
var cat1234 = 'cat1234';
var new1234 = cat1234.substring(3);
回答by Didier Ghys
You don't have to use jquery to do that, use simple javascript:
你不必使用 jquery 来做到这一点,使用简单的 javascript:
var txt = 'cat1234';
var txt2 = txt.substr(3);
回答by bjornd
回答by Dulith De Costa
JavaScript can do the trick.
JavaScript 可以做到这一点。
var s = 'cat1234';
console.log(s.toString().slice(3));
This will output: 1234
这将输出:1234