本文介绍了tinyMCE:删除最后插入的代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
限时送ChatGPT账号..以下内容:TinyMCE 编辑器固定大小,没有滚动条?
如何删除 tinyMCE 中最后插入的代码?
How can I remove the last inserted code in tinyMCE?
setup : function(ed){
ed.onKeyDown.add(function (ed, evt) {
var currentfr=document.getElementById(ed.id + '_ifr');
if (currentfr.contentDocument && currentfr.contentDocument.body.offsetHeight) { //ns6 syntax
currentfr.height = currentfr.contentDocument.body.offsetHeight + 26;
}
else if (currentfr.Document && currentfr.Document.body.scrollHeight) { //ie5+ syntax
currentfr.height = currentfr.Document.body.scrollHeight;
}
if( currentfr.height >= 156 ){
// Remove last inserted code here
}
});
},
因此,如果高度为 156 或更高,则应删除您刚刚输入的内容(代码).
So if the height is 156 or more, it should remove what you just typed (code).
我该怎么做?
推荐答案
我做了一些测试,这就是我想出的:
I made a few tests and this is what i came up with:
setup : function(ed){
ed.onKeyDown.add(function (ed, evt) {
var currentfr=document.getElementById(ed.id + '_ifr');
if (currentfr.contentDocument && currentfr.contentDocument.body.offsetHeight) { //ns6 syntax
currentfr.height = currentfr.contentDocument.body.offsetHeight + 26;
}
else if (currentfr.Document && currentfr.Document.body.scrollHeight) { //ie5+ syntax
currentfr.height = currentfr.Document.body.scrollHeight;
}
if (evt.keyCode != 8 && evt.keyCode != 46 && currentfr.height < 156){
ed.bookmark = ed.selection.getBookmark(2,true);
ed.latest_content = ed.getContent({format:'raw'});
}
});
ed.onKeyUp.add(function (ed, evt) {
var currentfr=document.getElementById(ed.id + '_ifr');
if (currentfr.contentDocument && currentfr.contentDocument.body.offsetHeight) { //ns6 syntax
currentfr.height = currentfr.contentDocument.body.offsetHeight + 26;
}
else if (currentfr.Document && currentfr.Document.body.scrollHeight) { //ie5+ syntax
currentfr.height = currentfr.Document.body.scrollHeight;
}
if( currentfr.height >= 156 && evt.keyCode != 8 && evt.keyCode != 46){
// Remove last inserted code here
// save and reset the caret using a bookmark
ed.setContent(ed.latest_content);
ed.selection.moveToBookmark(ed.bookmark);
ed.execCommand('mceCleanup');
}
});
},
这篇关于tinyMCE:删除最后插入的代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
更多推荐
[db:关键词]
发布评论