在CKEditor / Textbox中自动输入时,每个句子的第一个字母应为大写。 在多行文本框中,它运行良好。但CKeditor不工作。 我试过的代码如下。
var applySentenceCase = function(e) {
this.value = this.value.replace(/.+?[\.\?\!](\s|$)/g, function(letter) {
return letter.charAt(0).toUpperCase() + letter.substr(1).toLowerCase();
});
}
var capitalize = function(e) {
if (this.value.match(/^[a-z]/)) {
this.value = this.value.replace(/^./, function(letter) {
return letter.toUpperCase();
});
}
}
document.getElementById('TextBox1').addEventListener('keyup', capitalize);
document.getElementById('TextBox1').addEventListener('mouseup', capitalize);
document.getElementById('TextBox1').addEventListener('keyup', applySentenceCase);
document.getElementById('TextBox1').addEventListener('mouseup', applySentenceCase);
对于CKEditor
$(document).ready(function(){
var applySentenceCase = function (e) {
this.value = this.value.replace(/.+?[\.\?\!](\s|$)/g, function (letter) {
return letter.charAt(0).toUpperCase() + letter.substr(1).toLowerCase();
});
}
});
$(document).ready(function () {
var capitalize = function (e) {
if (this.value.match(/^[a-z]/)) {
this.value = this.value.replace(/^./, function (letter) {
return letter.toUpperCase();
});
}
}
});
document.getElementById('CKEditor1').addEventListener('keyup', capitalize);
document.getElementById('CKEditor1').addEventListener('mouseup', capitalize);
document.getElementById('CKEditor1').addEventListener('keyup', applySentenceCase);
document.getElementById('CKEditor1').addEventListener('mouseup', applySentenceCase);
</script>
</div>
答案 0 :(得分:0)
答案 1 :(得分:0)
试试这个
var str = "hello world";
str = str.toLowerCase().replace(/\b[a-z]/g, function(letter) {
return letter.toUpperCase();
});
alert(str);