在angularJs中文件上传

时间:2017-12-16 18:46:52

标签: angularjs

我正在尝试在angularJS中实现文件上传器,但条件是如果输入文件为空,则应该进行按摩。 我使用了以下代码:

if(var inputFileLength=document.getElementById("#id").value==0) 
alert ("input file is empty");

但它不起作用。所以请为此提供一些解决方案。

1 个答案:

答案 0 :(得分:1)

我相信event.target.files会获取文件名,因此无效。

我们可以使用.size获取所选文件的详细信息,并使用function selected(event) { let file = event.target.files[0]; if (file.size === 0) { alert("Its empty"); } else { alert("size is " + file.size); } }属性。

试试这个:

<input type="file" onchange="selected(event)" />
CGDisplayHideCursor (kCGNullDirectDisplay);
CGAssociateMouseAndMouseCursorPosition (false);
// ... handle events, move cursor by some scalar of the mouse movement
// ... using CGDisplayMoveCursorToPoint (kCGDirectMainDisplay, ...);
CGAssociateMouseAndMouseCursorPosition (true);
CGDisplayShowCursor (kCGNullDirectDisplay);

这不支持IE&lt; 11虽然......

https://developer.mozilla.org/en-US/docs/Web/API/File