jQuery 如何使用jquery从字符串中获取第一个字母

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/18887742/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-26 22:42:03  来源:igfitidea点击:

How to get first letter from string using jquery

jquery

提问by user2310209

I am poor knowledge in jquery. I have mentioned the script below

我对 jquery 的了解很少。我已经提到了下面的脚本

var header = $('.time'+col).text();
alert(header);

I got string as "109:00AM" from that how to get first letter such as 1. Could you please help me.

我从如何获得第一个字母(例如 1)中得到字符串为“109:00AM”。你能帮我吗。

回答by Gautam3164

Try with charAt(0)like

尝试charAt(0)喜欢

var header = $('.time'+col).text();
alert(header.charAt(0));

You can also use substringlike

你也可以使用substring

alert(header.substring(1));

And as @Jaisaid you can use slicealso like

正如@Jai所说,你也slice可以像这样使用

alert(header.slice(0,1));