简体   繁体   English

如何在Twitter Bootstrap WYSIWYG5中获取编辑器对象

[英]How to get editor object in twitter Bootstrap WYSIWYG5

I am using Bootstrap wysiwyg5 editor as a part of a form. 我使用Bootstrap wysiwyg5编辑器作为表单的一部分。

This text area happens to be a required field(should not be empty). 此文本区域恰好是必填字段(不应为空)。 I want to validate if the user has entered any value on to this field or not. 我想验证用户是否在此字段中输入了任何值。 I see that Bootstrap wysiwyg uses a Iframe to display the content. 我看到Bootstrap wysiwyg使用Iframe来显示内容。 I tried to access the content of the iframe's body in jQuery by doing this: 我尝试通过这样做来访问jQuery中iframe主体的内容:

$('.textarea.wysihtml5-editor').html()

but failed. 但失败了。

My question is: How do I check if the user has entered some text in this Bootstrap wysiwyg textarea. 我的问题是:如何检查用户是否在此Bootstrap wysiwyg textarea中输入了一些文本。 Please help me out. 请帮帮我。

Have you tried this question? 你试过这个问题吗?

How to access the content of an iframe with jQuery? 如何使用jQuery访问iframe的内容?

The answer from the question referenced above: 上面提到的问题的答案:

$("#myiframe").contents().find("#myContent")

Edited to add my original answer: 编辑添加我的原始答案:

$('.textarea.wysihtml5-editor').val()

wysiwyg editor does not works in bootstrap modal because it triggers before creating modal.. or something. wysiwyg编辑器在bootstrap模式中不起作用,因为它在创建模态之前触发..或者其他东西。 so the best way to do it is triggering the modal before wysiwyg editor. 所以最好的方法是在wysiwyg编辑器之前触发模态。

function showmymodal(){
$('#modal').modal('show');
$("#modal").html(' <div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
<h3 id="myModalLabel">modal header</h3></div>
<div class="modal-body">
<textarea id="textarea"></textarea>
</div>
<div class="modal-footer">
<button class="btn" data-dismiss="modal" aria-hidden="true">Close</button>
</div>
</form>');
$('#textarea').wysihtml5({
"font-styles": true, 
"emphasis": true,
"lists": true, 
"html": false, 
"link": true, 
"image": true, 
"color": true 
});
}

you can check on Tutorial website 你可以查看Tutorial网站

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM