TinyMCE验证给出错误:无法调用方法'getContent'的未定义
TinyMCE validation gives error: Cannot call method 'getContent' of undefined
我有一个带有微小mce的文本区域,我这样加载它:
$(document).ready(function () {
tinyMCE.init({
mode: "textareas",
...
此文本区域在表单中。我将表单提交按钮绑定到:
$('#btnSubmit').click(function() {
tinymce.triggerSave();
var editorContent = tinyMCE.get('Description').getContent();
if (editorContent == '' || editorContent == null)
{
$(tinymce.activeEditor.getBody()).css("background-color", '#ffeeee');
$(tinymce.activeEditor.getBody().parentNode).css("background-color", '#ffeeee');
$(tinymce.activeEditor.getBody().parentNode).css("border", '1px solid #ff0000');
}
});
在我的实体类中,我有Required
属性
我的目标是在模型无效时使tinyMCE后台red
。但我从题目中得到了错误
有什么帮助吗
因此,验证是有效的。如果我删除文本区域为空,请检查并保留颜色更改,它会更改。但问题是,当文本区域有东西时,我点击提交区域,首先变成红色,然后提交
如果验证失败,我是否可以采取措施?
在我看来,这听起来就像一个未定义的对象错误——代码无法解析这一行tinyMCE.get('Description').getContent();
。
你似乎在有时使用activeEditor
,有时不使用,所以我已经标准化了代码,所以你总是依赖activeEditor
——这意味着我已经删除了触发错误的行。您似乎还可以在使用tinymce
和tinyMCE
之间切换,这可能不会造成问题,但最好避免。。。所以我也把它标准化了。
如果没有更多地了解其余代码和标记的设置方式,就很难准确地判断发生了什么。我的更改能修复问题吗?
$('#btnSubmit').click(function() {
tinyMCE.triggerSave();
var editorContent = tinyMCE.activeEditor.getContent();
if (editorContent == '' || editorContent == null)
{
$(tinyMCE.activeEditor.getBody())
.css("background-color", '#ffeeee')
.parent()
.css({
"background-color": '#ffeeee',
"border": '1px solid #ff0000'
});
}
});
如果您不能控制TinyMCE的init方法,那么您可以遵循此解决方案。
jQuery(document).ready(function($) {
function myCustomSetContent( id, content ) {
// Check if TinyMCE is defined or not.
if( typeof tinymce != "undefined" ) {
var editor = tinymce.get( id );
// Check if TinyMCE is initialized properly or not.
if( editor && editor instanceof tinymce.Editor ) {
editor.setContent( text );
editor.save( { no_events: true } );
} else {
// Fallback
// If TinyMCE is not initialized then directly set the value in textarea.
//TinyMCE will take up this value when it gets initialized.
jQuery( '#'+id ).val( text );
}
return true;
}
return false;
}
function myCustomGetContent( id ) {
// Check if TinyMCE is defined or not.
if( typeof tinymce != "undefined" ) {
var editor = tinymce.get( id );
// Check if TinyMCE is initialized properly or not.
if( editor && editor instanceof tinymce.Editor ) {
return editor.getContent();
} else {
// Fallback
// If TinyMCE is not initialized then directly set the value in textarea.
// TinyMCE will take up this value when it gets initialized.
return jQuery( '#'+id ).val();
}
}
return '';
}
$(".class-to-update-content").on("click", function(e) {
myCustomSetContent( "tinymce-editor-id", "New Content in Editor" );
});
$(".class-to-get-content").on("click", function(e) {
$("div.class-to-display-content").html( myCustomGetContent( "tinymce-editor-id" ) );
});
});
参考编号:http://blog.incognitech.in/tinymce-undefined-issue/
相关文章:
- electronic BrowserWindow的最小高度和宽度在hide()show()方法之后不起作用
- 有没有任何方法可以将控制器从文件加载到ui路由器$stateProvider中
- 数组在递归方法中设置为null
- 打破承诺链的好方法是什么
- 在使用Polymer'加载所有json文件后执行方法;s的核心ajax
- 使用“;这个“;JavaScript原型方法中的关键字
- 序列化数据属性中对象的最可靠方法
- 使用Objective-C的JavaScript注入方法
- 有没有一种方法可以添加相同的项目val=“0”;4〃;到JavaScript中数组的每个对象
- 有没有一种方法可以防止img get请求使用css或js发生
- Javascript,有没有一种方法可以将数组写成没有逗号或空格的单个文本字符串
- toBoolean方法类似于toString
- 如何在单击复选框后调用控制器方法
- 是否有任何方法可以使用jQuery替换在数组中定义值的文本
- 递归使用 eval() 是检查程序执行的好方法吗?
- 如何在webView,Android中从@JavascriptInterface方法调用Javascript
- toLocaleDateString和toLocaleString方法不尊重机器时区
- 有条件更新d3.js力图中节点的最佳方法
- TypeError:在不兼容的接收器nodejs上调用了方法Uint8Array.length
- TinyMCE验证给出错误:无法调用方法'getContent'的未定义