javascript - Firefox:访问将文件从桌面拖放到 HTML 内容可编辑元素后生成的标签
问题描述
使用 Firefox,当我将图像文件从桌面拖放到 HTMLcontenteditable="true"
元素中时,<img>
会创建 a。
如何获得<img>
在将文件从桌面拖放到 contenteditable 元素后创建的内容,例如,为alt
属性设置值或更改其大小?
我的尝试:我认为也许有一种方法可以检索插入到 contentediable 元素中的最后一个(按顺序排列的)元素。
$("#editor").on("dragover", function (event) {
event.preventDefault();
event.stopPropagation();
$(this).addClass('dragging');
});
$("#editor").on("dragleave", function (event) {
event.preventDefault();
event.stopPropagation();
$(this).removeClass('dragging');
});
$("#editor").on("drop", function (event) {
//how to access here the <img> created after dropping
//the file from the desktop
}
p {
height: 700px;
width: 700px;
border: 1px solid black;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<p id="editor" contenteditable="true"></p>
解决方案
推荐阅读
- c - 从 BMP 文件中读取像素而不进行填充
- sequelize.js - Sequelize where 条件来自连接结果
- javascript - 如何从表单中检索值以供以后使用?
- c# - 将默认身份登录路由更改为自定义 asp.net 核心
- anylogic - 查封的资源物理位置
- python - 由 Latex 中的显示方程触发的文档字符串无效转义序列
- java - Java:有没有更有效的方法来做到这一点?检查素数
- mysql - 如何计算数据库列结果并将它们分组以实现可管理的输出
- r - 使用 tidyquant 库中的 tq_get 函数创建 for 循环以在 R 中按州获取失业申请?[包括图像和代码]
- c++ - 如何用子类对象初始化超类类型的指针?