javascript - 如何使用 Angularjs 在 Internet Explorer 中上传文件后清除文件名

标签 javascript css html angularjs

<input type="file" ng-model="myobj.file" ng-file-select="onFileSelect_filter($files)" id="fileButton" >
<button type="button" ng-click="start_Filter();" >Upload</button>

我的 onFileSelect_filter() 函数是这样的,

$scope.onFileSelect_filter = function($files){
   ....
};

我至少要在 Internet Explorer 中单击上传 按钮后清除文件名。

这个输入框不在表单里面 提前致谢...!!!

最佳答案

不幸的是,在这种情况下,将绑定(bind)的 $scope 变量等同于空字符串或 null 将不起作用。

虽然您可以通过下面提到的方法之一来实现它。

方法一:

您必须按字面意思替换 DOM 上的 html 单击(在您的情况下为上传)并将其恢复为上传前的状态。像这样..

 $scope.start_Filter = function(){
   // This is in the upload function post all your logic
   $("#fileButton").replaceWith("<input type='file' ng-model='myobj.file' ng-file-select='onFileSelect_filter($files)' id='fileButton' >").html();
};

注意:对于 replaceWith 函数中的所有 HTML 属性值,您必须使用单引号而不是双引号

方法二:

或者,您可以使用 JQuery 轻松清除文件名。像这样..

$scope.start_Filter = function(){
   // This is in the upload function post all your logic
   $("#fileButton").val('');
};

其中一个应该可以工作。请尝试一下,如果您遇到任何问题,请告诉我。

关于javascript - 如何使用 Angularjs 在 Internet Explorer 中上传文件后清除文件名,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23651741/

相关文章:

javascript - bootstrap模态框打开jquery位置选择器

css - 基于 Bootstrap 的组件 : show explaining content, 但在页面加载时关闭

javascript - 使用JsConstructor处理多个构造函数

JavaScript - 理解方法

javascript - Ng-Show 多次调用

css - 以 100% 的高度在 div 中滚动

javascript - 行内divs高度的划分

c# - 如果搜索框位于 _SiteLayout 页面(在标题 DIV 中),如何将搜索结果返回给用户

javascript - 在特定的转换值触发函数

javascript - 当不同的 div 展开时折叠所有其他 div