首页 > 解决方案 > 将图像上传到所见即所得编辑器并应用默认样式

问题描述

我为我的网站创建了一个所见即所得的文本编辑器,并正在尝试使用图像。

到目前为止,我已将图像上传并添加到我想要的文本编辑器中,使用如下所示:

$("#upload_wysiwyg_image").unbind("click").bind("click", function() {
    var formData = new FormData();
    var image_to_upload = document.getElementById("wysiwyg_image").files[0];
    formData.append("wysiwyg_image", image_to_upload);
    var xmlhttp = new XMLHttpRequest();
    xmlhttp.onreadystatechange = function(){
        if(this.readyState == 4 && this.status == 200){
            if(this.responseText.includes('uploaded')){
                var upload_string = this.responseText;
                var image_name = upload_string.replace("uploaded ","")
                var image_path = '../media/wysiwyg_images/'+image_name;
                execCmdWithArg('insertImage', image_path);
            }
        }
    };
    xmlhttp.open("POST", "upload_wysiwyg_image.php", true);
    xmlhttp.send(formData);
});

function execCmdWithArg (command, arg){
    richTextField.document.execCommand(command, false, arg);
}

我希望能够在插入图像时格式化图像。因此,例如设置一个max-width/max-height或能够选择一个float值进行定位。

这可以在插入时完成,还是我需要插入它,然后调用另一个函数来设置样式值?

如果有人能为此指出正确的方向,将不胜感激。

标签: javascriptjquerycsswysiwyg

解决方案


推荐阅读