在元素内部创建新元素
create new element inside element
我想在dropzone js中设置一个按钮移除链接的样式。我只是想让它看起来像带字形图标的引导按钮。
而是像这个一样的默认丢弃区域代码
Dropzone.prototype.defaultOptions = {
dictRemoveFile: "Remove file",
if (this.options.addRemoveLinks) {
file._removeLink = Dropzone.createElement("<a class='"dz-remove btn btn-default'" href='"javascript:undefined;'" data-dz-remove>" + this.options.dictRemoveFile + "</a>");
var custom = Dropzone.createElement("<div class='"custom'"></div>");
custom.appendChild(file._removeLink);
file.previewElement.appendChild(custom);
}
结果就像这个
<a class="dz-remove btn btn-default" href="javascript:undefined;" data-dz-remove="">Remove file</a>
我想要这样的结果
<div class="custom">
<button type="button" class="dz-remove btn btn-default" href="javascript:undefined;" data-dz-remove aria-label="Left Align">
<span class="glyphicon glyphicon-align-left" aria-hidden="true"></span>
</button>
</div>
所以我在dropzone.js中添加了一个类似的代码
file._removeLink = Dropzone.createElement("<button type='"button'" class='"dz-remove btn btn-default'" href='"javascript:undefined;'" data-dz-remove aria-label='"Left Align'">" + this.options.dictRemoveFile + "</button>");
var custom = Dropzone.createElement("<div class='"custom-btn'"></div>");
var span = Dropzone.createElement("<span class='"glyphicon glyphicon-align-left'" aria-hidden='"true'"></span>");
custom.appendChild(file._removeLink);
file.previewElement.appendChild(custom);
span.appendChild(file._removeLink);//i think i code this wrong//
file.previewElement.appendChild(span);//i think i code this wrong too//
目前我只成功地制作了
<div class="custom">
<button type="button" class="dz-remove btn btn-default" href="javascript:undefined;" data-dz-remove aria-label="Left Align">
</button>
</div>
问题只剩下标签span-interbutton(它没有显示)。
file._removeLink = Dropzone.createElement("<button type='"button'" class='"dz-remove btn btn-default'" href='"javascript:undefined;'" data-dz-remove aria-label='"Left Align'">" + this.options.dictRemoveFile + "</button>");
var custom = Dropzone.createElement("<div class='"custom-btn'"></div>");
var span = Dropzone.createElement("<span class='"glyphicon glyphicon-align-left'" aria-hidden='"true'"></span>");
file._removeLink.appendChild(span);
custom.appendChild(file._removeLink);
file.previewElement.appendChild(custom);
请尝试上面的代码。应该工作
相关文章:
- 有没有一种方法可以让内联事件处理程序在元素创建后立即执行
- 根据对多个数组唯一的元素创建一个新数组
- 使用Jquery从所有元素创建一个字符串
- 如何从html表单数组元素创建javascript数组
- 在 Backbone.js 中为集合中的一个元素创建详细信息页面
- 动态 DOM 元素创建
- 每 5 个元素创建一个新对象
- 下划线 从对象元素创建对象数组
- 从 2 个特定元素创建网格
- 维基百科如何从
- mongodb:如何为每个数组元素创建_id
- 如何为每 5 个元素创建一个 DIV
- 如何为自定义聚合物元素创建方法并在主应用程序中调用它
- jQuery元素创建,值传递
- 我无法基于实际的 HTML 元素创建类
- 在 jQuery 中迭代数组时,每隔一个元素创建新列表
- Mouseover/out难题上的JS元素创建/删除
- 为Angular指令创建的元素创建名称
- Javascript/jquery从具有相同rel的元素创建数组
- 如何使用DOM元素创建表单的副本