我使用 jquery 插件来生成富文本编辑器。该编辑器生成如下结构:
<div id="editor" ... >
...
<iframe>
<!DOCTYPE html>
<html>
<head>...</head>
<body>
//some important content here and I need to get them
</body>
</html>
</iframe>
</div>
现在,我想将 iframe 体内的所有内容作为 String 获取。我测试了 $("#editor").contents().find("body")
,但这返回了一个对象,而不是字符串。还尝试了 $("#editor").contents().find("body").outerHTML
,但这返回我 undefined
。我怎样才能做到这一点?请帮我。感谢您抽出时间。
编辑:
我使用SCEditor插入。正如 Ramesh 所说,我使用了 val() 方法,但仍然在 firebug 控制台中返回我(空字符串)。这是我的代码:
var instance = $("textarea").sceditor({
plugins: "bbcode",
style: "../../editor/minified/jquery.sceditor.default.min.css",
//some othe options
});
$("#save").click(function(){
console.log(instance.val());
});
正如 Ramesh 所建议的,我使用了 $('textarea').seditor('instance').val()
并且它有效。
最佳答案
在SCEditor中要获取富文本框的值,您必须使用.val
方法
val() Since: 1.3.5
Gets the current value of the editor.
This will return the filtered HTML from the WYSIWYG editor or the unfiltered contents of the source editor.
If using a plugin that filters the HTML like the BBCode plugin, this will return the filtered HTML or BBCode in the case of the BBCode plugin.
Syntax
var val = instance.val();
Return Type:
String
The filtered value of the editor
关于javascript - 获取 iframe 内容作为字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30116410/