TinyMCE Javascript验证
我正在一个网站上建立一个发布系统,但是每当我在我的文本区域中包含TinyMCE插件时,我都会遇到一个奇怪的问题。我在JavaScript中验证输入,看它是否为空(参见代码blow)。如果没有TinyMCE,它可以正常工作,但是当我包含TinyMCE插件时,这些值不会返回任何结果TinyMCE Javascript验证,javascript,jquery,html,tinymce,Javascript,Jquery,Html,Tinymce,我正在一个网站上建立一个发布系统,但是每当我在我的文本区域中包含TinyMCE插件时,我都会遇到一个奇怪的问题。我在JavaScript中验证输入,看它是否为空(参见代码blow)。如果没有TinyMCE,它可以正常工作,但是当我包含TinyMCE插件时,这些值不会返回任何结果 ('#form_createblog').bind('submit',function(){ var titel = $('input[name=titel]').val(); var categorie
('#form_createblog').bind('submit',function(){
var titel = $('input[name=titel]').val();
var categorie = $('select[name=categorie]').val();
var synopsis = $('textarea[name=synopsis]').val(); // this remains blank when tinymce is included
var inhoud = $('textarea[name=inhoud]').val(); // this remains blank when tinymce is included
console.log(titel);
console.log(categorie);
console.log(synopsis);
console.log(inhoud);
var proceed = true;
if (titel==""){
$('input[name=titel]').css({'border':'2px solid red'});
proceed = false;
}
if (categorie==""){
$('select[name=categorie]').css({'border':'2px solid red'});
proceed = false;
}
if (synopsis==""){
$('textarea[name=synopsis]').css({'border':'2px solid red'});
proceed = false;
}
if (inhoud==""){
$('textarea[name=inhoud]').css({'border':'2px solid red'});
proceed = false;
}
more code leading up to ajax call ...
TinyMCE文件如下所示
tinyMCE.init({
mode : "textareas",
theme : "advanced",
plugins : "paste,advimage",
width : "100%",
height : "200",
relative_urls : false,
element_format : "html",
doctype : '<html>',
theme_advanced_blockformats : "p,h1,h2",
theme_advanced_buttons1 : "formatselect,bold,italic,|,justifyleft,justifycenter,justifyright,|,bullist,numlist,|,link,unlink,cleanup,|,cut,copy,paste,pastetext,|,image,hr,removeformat",
theme_advanced_buttons2 : "",
theme_advanced_buttons3 : "",
theme_advanced_toolbar_location : "top",
theme_advanced_toolbar_align : "left",
theme_advanced_statusbar_location : "bottom",
theme_advanced_resizing : false,
theme_advanced_resize_horizontal : false,
theme_advanced_resizing_use_cookie : false,
inline_styles : true
});
tinyMCE.init({
模式:“文本区域”,
主题:“高级”,
插件:“粘贴,advimage”,
宽度:“100%”,
高度:“200”,
相对URL:false,
元素_格式:“html”,
doctype:“”,
主题\u高级\u块格式:“p、h1、h2”,
主题高级按钮1:“格式选择、粗体、斜体、|、左对齐、居中对齐、右对齐、|、粗体、数字列表、|、链接、取消链接、清理、|、剪切、复制、粘贴、粘贴文本、|、图像、hr、移除格式”,
主题\高级\按钮2:“”,
主题\高级\按钮3:“”,
主题\高级\工具栏\位置:“顶部”,
主题\高级\工具栏\对齐:“左”,
主题\高级\状态栏\位置:“底部”,
主题\u高级\u大小调整:错误,
主题\u高级\u调整大小\u水平:false,
主题\u高级\u调整大小\u使用\u cookie:false,
内联样式:true
});
我的html是这样的
<form name="maakblogpost" id="form_createblog" method="post" onsubmit="return false;">
...................................
<div class="row">
<div class="col-md-4">
<span class="titel">Samenvatting van de blogpost</span>
</div>
<div class="col-md-7">
<textarea name="synopsis" value=""></textarea>
</div>
</div>
<div class="row">
<div class="col-md-4">
<span class="titel">De daadwerkelijke inhoud van de blogpost</span>
</div>
<div class="col-md-7">
<textarea name="inhoud" value=""></textarea>
</div>
</div>
<button class="submit button" name="maakblogpost" type="submit" id="left_btn">Sla uw blog op</button>
</form>
...................................
Samenvatting van de blogpost
博格波斯特酒店
Sla-uw博客
我怀疑这是我自己代码中的一个错误,但为了安全起见,我将其发布在这里,因为当我没有包含TinyMCE时,验证工作正常
这是tinymce版本3.5.7顺便说一句,这和它有关系吗?有人知道新版本上是否也会出现这种情况吗(我想他们现在是4点左右)TinyMCE在提交表单之前不会设置textarea值,因此需要手动调用
TinyMCE.triggerSave()代码>在获取值之前。谢谢!触发者成功了。我认为TinyMCE调用save函数有点奇怪,因为它构建在一个textarea上,而这不需要save。然而,你的回答起了作用。非常感谢。