这是一个测试。这又是一项测试。这也是新的测试。
这是测试。这又是一项测试。这是新的测试。
最佳答案
为此您不需要 jQuery。您可以使用 Javascript string
和 array
函数。
- 用
.
分割字符串,以分隔不同的句子 - trim 每个句子
- 首字母大写
- 通过
加入。
var str = 'this is a test. this is one more test. and this also new test.';
var newStr = str.split('.').map(function(el) {
el = el.trim();
return el.substr(0, 1).toUpperCase() + el.substr(1);
}).join('. ');
alert(newStr.trim());
关于javascript - JavaScript/Jquery 中句子的第一个字母大写,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31555376/