运行一个根据输入长度禁用表单提交按钮的基本功能。
我正在使用这个:
// check if the newpost text area in empty on page load and also input change
$(document).ready(function(){
disableNewPost();
$('#newpost').keyup(disableNewPost);
});
// disable new post submit button if the new post ckeditor is empty
function disableNewPost() {
if ($('#newpost').val().length > 0) {
$(".addnewpostbtn").prop("disabled", false);
} else {
$(".addnewpostbtn").prop("disabled", true);
}
}
这适用于普通文本区域,请参见此处:http: //jsfiddle.net/QA22X/
但是在使用 CKEditor 时它不起作用。
我已经完成了我的研究,但找不到任何有效的方法。
我看到了这个并尝试了它:
// check if the newpost text area in empty on page load and also input change
$(document).ready(function(){
disableNewPost();
var e = CKEditor.instances['#newpost']
e.on( 'keyup', function( event ) {
disableNewPost();
});
});
// disable new post submit button if the new post ckeditor is empty
function disableNewPost() {
var value = CKEDITOR.instances['#newpost'].getData();
if ($(value).length > 0) {
$(".addnewpostbtn").prop("disabled", false);
} else {
$(".addnewpostbtn").prop("disabled", true);
}
}
但这也行不通。
对此有什么帮助吗?