- <html>
- <head>
- <script type="text/javascript">
- var isIE = /msie/i.test(navigator.userAgent) && !window.opera;
- function fileChange(target) {
- var fileSize = 0;
- if (isIE && !target.files) {
- var filePath = target.value;
- var fileSystem = new ActiveXObject("Scripting.FileSystemObject");
- var file = fileSystem.GetFile (filePath);
- fileSize = file.Size;
- } else {
- fileSize = target.files[0].size;
- }
- var size = fileSize / 1024;
- if(size>10000){
- alert("附件不能大于10M");
- }
- }
- </script>
- </head>
- <body>
- <input type="file" name="contractFileName" style="width: 500px;" onchange="fileChange(this);"/>
- </body>
- </html>
js判断上传文件大小
最新推荐文章于 2021-08-06 10:45:42 发布
本文介绍如何使用JavaScript在文件上传过程中实现10MB大小限制,并通过判断浏览器类型进行针对性处理,确保用户体验。
403

被折叠的 条评论
为什么被折叠?



