Javascript html编辑器可以插入jQuery元素吗?
我一直在使用javascript函数制作html编辑器: 因此,我有一个非常基本的编辑器,带有一个“粗体”按钮,我可以用它将选中的任何文本粗体化,这很好(我也有许多其他按钮,但为了代码的简单和简短,我错过了它们)Javascript html编辑器可以插入jQuery元素吗?,javascript,jquery,html,contenteditable,execcommand,Javascript,Jquery,Html,Contenteditable,Execcommand,我一直在使用javascript函数制作html编辑器: 因此,我有一个非常基本的编辑器,带有一个“粗体”按钮,我可以用它将选中的任何文本粗体化,这很好(我也有许多其他按钮,但为了代码的简单和简短,我错过了它们) var-editorDoc; 函数InitEditable(){ var editor=document.getElementById(“编辑器”); editorDoc=editor.contentWindow.document; var editorBody=editorDoc.
var-editorDoc;
函数InitEditable(){
var editor=document.getElementById(“编辑器”);
editorDoc=editor.contentWindow.document;
var editorBody=editorDoc.body;
如果(editorBody中的“contentEditable”){
editorBody.contentEditable=true;
}
否则{
if(editorDoc中的“设计模式”){
editorDoc.designMode=“on”;
}
}
}
函数ToggleBold(){
editorDoc.execCommand('bold',false,null);
}
大胆的
然而,我真正感兴趣的是能够实现一个按钮,这个按钮可以在按下时插入,比如说,手风琴
这样就必须添加其他脚本(我想)才能运行每个手风琴(如果您有多个手风琴的话)
虽然我自己还没有尝试过这么做,但我希望在开始之前能了解一下这是否可行。只要你定义了一些模板,你就可以添加所有内容。我是否需要以不同的方式初始化任何内容,还是应该按照上面的设置方式进行?你必须定义模板和需要插入、编辑等的函数。这需要很多时间。
<head>
<script>
var editorDoc;
function InitEditable () {
var editor = document.getElementById ("editor");
editorDoc = editor.contentWindow.document;
var editorBody = editorDoc.body;
if ('contentEditable' in editorBody) {
editorBody.contentEditable = true;
}
else {
if ('designMode' in editorDoc) {
editorDoc.designMode = "on";
}
}
}
function ToggleBold () {
editorDoc.execCommand ('bold', false, null);
}
</script>
</head>
<body onload="InitEditable ();">
<button type="button" onclick="ToggleBold ();">Bold</button>
<iframe contenteditable="true" id="editor"></iframe>
</body>