【问题标题】:How to get editor object in twitter Bootstrap WYSIWYG5如何在 twitter Bootstrap WYSIWYG5 中获取编辑器对象
【发布时间】:2013-06-02 14:27:26
【问题描述】:

我正在使用 Bootstrap wysiwyg5 编辑器作为表单的一部分。

此文本区域恰好是必填字段(不应为空)。我想验证用户是否在此字段上输入了任何值。我看到 Bootstrap wysiwyg 使用 iframe 来显示内容。我试图通过这样做来访问 jQuery 中 iframe 正文的内容:

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

但失败了。

我的问题是:如何检查用户是否在此 Bootstrap 所见即所得文本区域中输入了一些文本。请帮帮我。

【问题讨论】:

  • 你是如何初始化它的?
  • 除非我遗漏了什么,否则我在他们的演示中看不到任何 iframe。这只是一个 div,即contenteditable
  • 是的,我看到一个 iframe 用于显示内容。
  • mindmup.github.io/bootstrap-wysiwyg - 没有 iframe。这是<div id="editor" contenteditable="true"></div>
  • @lan ah.. 你的似乎与我使用的有点不同:jhollingworth.github.io/bootstrap-wysihtml5

标签: javascript twitter-bootstrap textarea wysiwyg


【解决方案1】:

你试过这个问题吗?

How to access the content of an iframe with jQuery?

上述问题的答案:

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

编辑添加我原来的答案:

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

【讨论】:

  • 哇!!它奏效了!!只有上帝知道我已经坚持了多久......非常感谢!
  • 你能把你之前写的陈述包括在你的答案中,以便我接受答案吗?
  • 我之前写的内容是在我意识到您指的是 iframe 之前。我需要在那里写一些代码才能被接受吗?
  • 我刚刚从@mbillard 引用的链接中附加了答案。
  • 哦,太好了。很高兴我能帮助你。我敢肯定,我们都知道当你离你只有一步之遥时,在某物上旋转是什么感觉。我也添加了我的原始答案。
【解决方案2】:

所见即所得编辑器在引导模式中不起作用,因为它在创建模式之前触发.. 或其他东西。所以最好的方法是在所见即所得编辑器之前触发模态。

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 
});
}

你可以去看看 Tutorial website

【讨论】:

  • 欢迎来到 Stack Overflow。请在您的答案中总结链接;这样,如果链接失效,答案也不会完全没用。
  • @Debashis Dip 感谢您的回答。这不是我关心的问题,我没有尝试让 WYSIHTML5 在模态中工作。
  • 抱歉,要检查 iframe val,您应该使用 $("#textarea").val();
猜你喜欢
  • 1970-01-01
  • 2016-05-18
  • 2014-03-20
  • 1970-01-01
  • 2022-12-06
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2022-10-18
相关资源
最近更新 更多