javascript - 将图像上传到所见即所得编辑器并应用默认样式
问题描述
我为我的网站创建了一个所见即所得的文本编辑器,并正在尝试使用图像。
到目前为止,我已将图像上传并添加到我想要的文本编辑器中,使用如下所示:
$("#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
值进行定位。
这可以在插入时完成,还是我需要插入它,然后调用另一个函数来设置样式值?
如果有人能为此指出正确的方向,将不胜感激。
解决方案
推荐阅读
- git - 警告:refname 'HEAD' 不明确 - 但没有 HEAD 分支
- azure - Azure Kubernetes 服务超时,API 调用出现 500 个状态码
- javascript - 如何从网页中的元素中获取内容并将其显示在我的 html 页面中?
- typescript - NestJS / TypeORM 本地化
- javascript - How to print array data inside a table
- c# - 使用从 asmx wsdl 生成的代理层时如何绕过证书验证
- c# - "Analyzer with Code Fix" project template is broken
- java - 我们如何想象记忆中的继承?
- reactjs - 反应路由器不改变子页面
- react-native - React 左侧出现的原生三点菜单