开发者

XHTML Text input, CSS text-transform and JavaScript [duplicate]

This question already has answers here: 开发者_运维技巧 Closed 11 years ago.

Possible Duplicate:

Convert string to Pascal Case (aka UpperCamelCase) in Javascript

I'm doing some quite basic stuff here so bear with me..

I'm using an XHTML text input to get a users name. I'm then showing an alert message via javascript. I've made it so that the first letters of the users names are capitalised via text-transform: capitalize; but javascript reads the original entry and doesn't take account of this.

What is the simplest solution I can use so that the alert is also capitalised in the same way? Preferably the less code the better so I can understand it easily :)

Thanks


var titleCase = 'make me look GOOD'.toLowerCase().replace(/(?:^|\s)[a-z]/g, function(match) {
    return match.toUpperCase();
});

jsFiddle.

Output

Make Me Look Good
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜