javascript - Sweet Alert后的文件上传窗口

标签 javascript html angularjs sweetalert

用例:

  • 我正在尝试改变 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/

相关文章:

javascript - ionic + Angular : Unable to clear input field

html - 将 DIV 居中对齐并彼此相邻

javascript - 观看模态时使用物化 css 类将填充添加到我的页面

javascript - JavaScript 中的可伸缩标题

javascript - 如何调试 Angularjs ng-route 和 Threejs 崩溃/问题?

.net - 在数据库中保存格式化文本的有意义的格式是什么?

javascript - 尝试通过 AJAX 验证 Laravel Form 时出现错误 422

javascript - firebase 登录谷歌电子邮件

javascript - 在jQuery插件中正确扩展用户选项

javascript - 如果出现确认框,控制页面移至顶部