sai*_*can 4 javascript jquery event-handling ckeditor
如何在达到最大字符限制后阻止用户输入新字符?
Ckeditor charcount插件只显示剩余的字符,我希望它停在0.但它会减去整数.
这是我的HTML代码.
<textarea id="myTextEditor1" name="myTextEditor"></textarea>
<script type="text/javascript">
CKEDITOR.replace('myTextEditor1', {
height: 200,
extraPlugins: 'charcount',
maxLength: 10,
toolbar: 'TinyBare',
toolbar_TinyBare: [
['Bold','Italic','Underline'],
['Undo','Redo'],['Cut','Copy','Paste'],
['NumberedList','BulletedList','Table'],['CharCount']
]
});
</script>
Run Code Online (Sandbox Code Playgroud)
我必须使用onChange插件吗?如果我必须如何限制用户输入新字符?
jaz*_*ZRo 10
我使用了ckeditor jQuery适配器.
<textarea id="myTextEditor1" name="myTextEditor"></textarea>
<script type="text/javascript">
$(function () {
var myEditor = $('#myTextEditor1');
myEditor.ckeditor({
height: 200,
extraPlugins: 'charcount',
maxLength: 10,
toolbar: 'TinyBare',
toolbar_TinyBare: [
['Bold','Italic','Underline'],
['Undo','Redo'],['Cut','Copy','Paste'],
['NumberedList','BulletedList','Table'],['CharCount']
]
}).ckeditor().editor.on('key', function(obj) {
if (obj.data.keyCode === 8 || obj.data.keyCode === 46) {
return true;
}
if (myEditor.ckeditor().editor.document.getBody().getText().length >= 10) {
alert('No more characters possible');
return false;
}else { return true; }
});
});
</script>
Run Code Online (Sandbox Code Playgroud)
keyCode检查是允许退格和删除按键.要使用jQuery适配器,请不要忘记插入它:
<script src="/path-to/ckeditor/adapters/jquery.js"></script>
Run Code Online (Sandbox Code Playgroud)