我在我的网页中使用openwysiwyg编辑器。我想清空里面的内容。我用过
$('#report').val('');但这并不能澄清这一点。
编辑器创建一个iframe并更新其中的内容,同时同步。
我该如何清理它呢?
发布于 2009-06-12 04:35:06
您可能需要提供更多的信息- html本身将非常有用,但我将假设report是您需要清除的文本区的id。
如果它是一个普通的文本区域,那么你的代码应该可以正常工作。
如果(就像保罗在评论中提到的那样)它被openwysiwyg编辑器修改了,那么它很可能会被转换成一个带有自己的超文本标记语言页面的iFrame。操作iFrame要困难得多。
看起来是这样的。
看一下这个例子,看看它是否能帮助您引用iFrame本身:http://www.bennadel.com/index.cfm?dax=blog:1592.view
这是openwysiwyg附带的example.html的黑客摘录:
<script type="text/javascript">
// Use it to attach the editor to all textareas with full featured setup
//WYSIWYG.attach('all', full);
// Use it to attach the editor directly to a defined textarea
WYSIWYG.attach('textarea1'); // default setup
WYSIWYG.attach('textarea2', full); // full featured setup
WYSIWYG.attach('textarea3', small); // small setup
// Use it to display an iframes instead of a textareas
//WYSIWYG.display('all', full);
function getIFrameDocument( id )
{
var iframe = document.getElementById(id);
if (iframe.contentDocument) {
// For NS6
return iframe.contentDocument;
} else if (iframe.contentWindow) {
// For IE5.5 and IE6
return iframe.contentWindow.document;
} else if (iframe.document) {
// For IE5
return iframe.document;
} else {
return null;
}
}
function clearcontents()
{
getIFrameDocument('wysiwygtextarea1').body.innerHTML = '';
}
</script>然后在页面的某个地方,我得到了一个清晰的按钮(实际上是div):
<div style="width:120px;height:20px;background:#ff0000;text-align:center;display:block;" onclick="clearcontents();">Clear!</div>请注意,文本区的id以wysiwyg为前缀。这是iFrame的名称。
我已经在Firefox中测试过了,但目前没有其他测试。获取我在网上某个地方找到的iFrame的代码,所以希望它能在其他浏览器上运行:)
发布于 2009-06-12 05:05:30
这是可行的,但很丑陋:
var frame = WYSIWYG.getEditor('--ENTER EDITOR NAME HERE--');
var doc = frame.contentWindow.document;
var $body = $('html',doc);
$body.html('');调用attach时,将--ENTER EDITOR NAME HERE--替换为您传递给编辑器的任何内容。
发布于 2009-06-12 04:33:19
我相信这是可行的
$('#report').text('');https://stackoverflow.com/questions/984992
复制相似问题