开发者

jQuery/javascript delete suffix of variable

I have a variable set to retrieve the id of a specific element which开发者_StackOverflow中文版 is "PubRecNum-1" (the number is also variable and will change depending on the record number). What I'm needing is a way to only take the first 3 letters of the variable "Pub" (needed for comparison purposes).

Any ideas?


You can get those letters using substring() or slice():

var str = "PubRecNum-1";
alert(str.substring(0, 3)); // -> "Pub"
alert(str.slice(0, 3)); // -> "Pub"


Javascript's substring() or substr() is used for exactly this

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜