我写了一个JavaScript代码来动态创建主轴编辑器。首先,工具栏按钮根本不起作用。因此,我从创建的单个编辑器复制了“ ql-toolbar” -div,并在创建编辑器之前构建了html代码。现在大多数按钮都可以使用,除了颜色,字体,背景颜色和链接。有人可以帮助我让按钮起作用吗?对不起,我英语不好。
这是我的js代码:
var toolbarhtml = //Here is the html code of the ql-toolbar div
function CreateBoxes(Amount, Editable, BoolToolbar) {
var box = document.getElementById("controlAddIn");
box.innerHTML += "<div id=\"wrapper\">";
var wrapper = document.getElementById("wrapper");
for (var i = 0; i < Amount; i++) {
var editor = "editor" + (i + 1);
var header = "heading" + (i + 1);
wrapper.innerHTML += "<div class=\"wrapped\" id=\"div" + (i + 1) + "\"><h2 class=\"navHeader2\" id=\"" + header + "\"></h2>";
var div = document.getElementById("div" + (i + 1));
var preScript = "<div class=\"editors\" id=\"" + editor + "\">";
var postScript = "</div>"
var fullScript = preScript + "" + postScript;
if(BoolToolbar){
div.innerHTML += toolbarhtml;
}
div.innerHTML += fullScript;
wrapper.innerHTML += "</div>";
}
box.innerHTML += "</div>";
var divs = document.getElementsByClassName("editors");
if(BoolToolbar){
var toolbars = document.getElementsByClassName("ql-toolbar");
var custombuttons = document.getElementsByClassName("customspan");
}
for(var j = 0; j < divs.length; j++){
var quill;
if(BoolToolbar){
//custombuttons[j].innerHTML += "<button class=\"custombutton\" onclick=\"text(" + (j + 1) + ")\">T</button>";
//ignore the line above, thats just for my custom button, which is working fine
quill = new Quill(divs[j], {
modules: {
toolbar: toolbars[j]
},
theme: 'snow'
});
} else {
quill = new Quill(divs[j], {
modules: {
},
theme: 'bubble'
});
}
if(!Editable){
quill.disable();
}
}
}
附言:如果您需要var工具栏上的html代码,请告诉我。但是要警告,它非常长且令人困惑。