我正在制作一个网站,我有一个功能允许用户拖放特定类型的文件,然后获取有关该文件的更多信息。除了一件事,我的代码运行良好。我有一个警告框(实际上是一个 SweetAlert 框),其中显示了用户想要查看的信息。我有处理文件的代码,然后制作一个 json,最后制作具有三个按钮的 html 代码,每个按钮都有自己的函数,驻留在我的 javascript 中。我的问题是,我希望用户能够单击三种不同类型的按钮来执行各种操作,但是 SweetAlert 框充当我网站顶部的新 html 页面并且有自己的范围。警报框无法识别我的 javascript 函数存在,因此它什么也不做。
为了调用这个警报,我使用了一个 ajax 请求。这是调用该函数的成功消息。数据是 json 格式。
success: function(data) {
informUser(printData(data))
},
这是我打印 json 格式和按钮的 javascript。为了简单起见,我没有包含一些部分,所以如果我的代码中的内容没有意义,请告诉我。
function printData(data) {
var str = ""
str += '<p>Your file was added!</p>';
str += "<p>You can access it at these locations: </p>";
str += "<button onclick='changeView()'/>View all files</button>";
str += "<button onclick='downloadCurrent()'/>Download the current file</button>";
str += '<p>To upload this, click here: </p>';
str +='<button onclick="addAsNewButton()">Add As New</button>';
return str;
};
这是我的 SweetAlert,它在某种程度上充当了自己的 javascript 文件。
var informUser = function(message){
swal({title: "Congrats on uploading a file!", html: true, text: message, type: "info" });
};
我正在阅读有关 SweetAlerts 如何在其中包含功能的示例,我需要帮助调用我的。如果有人认为他们可以帮助我,我愿意解释可能需要的任何其他内容,包括我尝试过和失败的事情。我什至会感谢有关如何解决此问题的一般想法。这是 SweetAlert 文档http://t4t5.github.io/sweetalert/的链接。