gpt4 book ai didi

与 ckeditor 集成的文本区域的 jquery 验证

转载 作者:行者123 更新时间:2023-12-03 22:43:04 25 4
gpt4 key购买 nike

我有一个文本区域

<td><textarea id="event-body" name="body">
<p class="error"></p>

与 CKEDITOR 集成

CKEDITOR.replace("event-body")

和 jquery 验证 plugin 。代码是这样的

$('#event').validate({
rules:{
name:{
required: true
},
},
messages:{
body:{
required: "event body is required"
}
},
errorPlacement: function(error, element){
$(element).each(function (){
$(this).parent('td').find('p.error').html(error);
})
});

代码工作得很好,但是当我输入 textarea 元素时,我仍然会收到错误消息,直到我单击它两次。即我必须提交页面两次,这样即使 textarea 不为空,我也不会出现错误消息。

有没有办法顺利验证(无需点击两次)。

最佳答案

看看here

基本上你需要打电话

CKEDITOR.instances.editor1.updateElement();

运行验证之前。

只需将 editor1 替换为您的文本区域的名称即可。

然后调用

$(myformelement).validate();

编辑

$("#my-form-submit-button").click(function(e){
e.preventDefault();
CKEDITOR.instances.event-body.updateElement();
$('#event').validate({
...options as above..
});o
})

关于与 ckeditor 集成的文本区域的 jquery 验证,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5126565/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com