我要实现的目标是在js
中创建图像选择器。
我已经尽一切努力找回了网址图片。
这是我目前的工作流程。
我在html内这样创建一个空的div:
<div id="UploadBox" hidden></div>
然后我添加如下脚本:
$("#ChangeTumbnailBtn").click(function () {
var up = new Upload(UploadBox);
$("#UploadBox").show();
//My idea is to wait here until Upload class says something and then proceed with code and get up.Response
});
我的Upload
类是这样的:
class Upload {
constructor(ContainerID) {
var maincontainer = ContainerID;
var SelectedImageUrl;
$(maincontainer).css("position", "absolute");
$(maincontainer).css("top", $(window).height() / 100 * 2);
$(maincontainer).css("left", $(window).width() / 100)
$(maincontainer).css("height", $(window).height() / 100 * 96);
$(maincontainer).css("width", $(window).width() / 100 * 98);
$(maincontainer).css("padding", "15px");
$(maincontainer).css("-webkit-box-sizing", "border-box");
$(maincontainer).css("-moz-box-sizing", "border-box");
$(maincontainer).css("box-sizing", "border-box");
$(maincontainer).css("border", "solid 1px");
$(maincontainer).css("background-color", "#e0e0e0");
$(maincontainer).css("border-radius", "10px");
$(maincontainer).append("<button id='UploadButtonClose' style='position: absolute; right: 15px; border: none; background-color: transparent'>X</button>");
$(maincontainer).append("</div>");
$(maincontainer).append("<h2 style='margin: 0'>Galery</h2>");
$(function () {
$.ajax({
type: "GET",
url: "/Gallery/GetAll",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (data) {
for (var i = 0, len = data.length; i < len; i++) {
$(maincontainer).append("<img class='selectingImage' style='float: left; margin: 10px; max-width: 200px; max-height: 200px;' src='/Uploads/Images/" + data[i] + "' />");
}
},
error: function () {
alert("ERROR");
}
});
$("#UploadButtonClose").click(function () {
$(maincontainer).html("");
$(maincontainer).fadeOut();
delete this;
});
$(".selectingImage").click(function () {
SelectedImageUrl = this.attr("src");
});
});
}
}
所以我该如何等待课程“关闭”或以某种方式对我说“嘿,现在继续您的代码”,在我评论//My idea...