用例:
我正在尝试改变
window.alert
甜蜜警报。当我使用
window.alert
时,文件上传窗口前出现警告弹出窗口,然后单击“确定”,出现文件上传窗口。- 但是,改变后
window.alert
到甜蜜警报时,文件上传窗口同时出现。
<label for="ScanFile"><i class="fa fa-upload" style='cursor: pointer;' ng-click="uploadAlert(row)"></i></label> <input id="ScanFile" type="file"/>
当用户点击标签时,会出现Sweet-alert,然后用户可以选择文件。
uploadAlert():
$scope.uploadAlert = function() {
$window.alert(~~~~~~);
}
如何解决这个问题?
最佳答案
<label for="ScanFile"><i class="fa fa-upload" style='cursor: pointer;' ng-click="uploadAlert(event, row)"></i></label>
<input id="ScanFile" type="file"/>
你的 uploadAlert() 函数将类似于,
$scope.uploadAlert = function(e) {
e.preventDefault(); // this will prevent the upload dialog from opening
swal(); // sweetalert popup
}
现在您可以通过编程方式单击 <input id="ScanFile" type="file"/>
使用 id,在关闭 sweetalert 对话框后打开对话框。
document.getElementById("ScanFile").click();
例如:
$scope.uploadAlert = function(e) {
e.preventDefault(); // this will prevent the upload dialog from opening
swal({
title: 'Demo',
text: 'Demo',
showCancelButton: true,
confirmButtonText: 'Submit',
},
function() {
document.getElementById("ScanFile").click();
});
});
}
关于javascript - Sweet Alert后的文件上传窗口,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51870820/