我使用 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插件。正如拉梅什所说,我使用了val()
方法,但仍然(an empty string)
在萤火虫控制台中返回我。这是我的代码:
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').sceditor('instance').val()
并且效果很好。