如何使用jQuery从字符串中获取第一个字母 [英] How to get first letter from string using jquery

查看:1012
本文介绍了如何使用jQuery从字符串中获取第一个字母的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不太了解jquery.我已经在下面提到了脚本

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

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

从如何获取第一个字母(例如1),我得到了字符串"109:00AM". 你能帮我吗?

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

推荐答案

尝试使用charAt(0)之类的

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

您也可以像使用substring一样

alert(header.substring(1));

正如 @Jai 所说,您也可以使用slice

And as @Jai said you can use slice also like

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

这篇关于如何使用jQuery从字符串中获取第一个字母的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆