js获取HTML5 多文件file选择的数量

js获取HTML5 多文件file选择的数量,第1张

<form onsubmit="return fileCountCheck(this)">

<input type="file" name="mulUp[]" multiple="multiple" required="required" />

<input type="submit" />

</form>

<script type="text/javascript">

function fileCountCheck(objForm){

if (window.File && window.FileList) {

var fileCount = objForm["mulUp[]"].files.length

if(fileCount > 10){

window.alert('文件数不能超过晌行10个,你选择了' + fileCount + '个')

}

else {

window.alert('符合规定')

}

}

else {

window.alert('抱歉,你的浏览器不支持FileAPI,请升级浏览器!')

}

return false

}

</script>

扩展资料:

java获取路径文件名的方法总结

1、文件路径获取

Thread.currentThread().getContextClassLoader().getResource(“”) //获得资源文件(.class文件)所在路径

ClassLoader.getSystemResource(“”)

ClassName.class.getClassLoader().getResource(“”)

ClassName.class .getResource(“/”)

ClassName.class .getResource(“”) // 获得当前类所在路径

System.getProperty(“user.dir”) // 获得项目根目录的绝对路径

System.getProperty(“java.class.path”) //得到类路径和包路径

其中ClassName为类名。

2、文件名获取

String fName =” D:\java\workspace\netmanager01\resources\mibfiles\wtView.mib “

(“\”,java中需要转义)

第一种:

File tempFile =new File( fName .trim())

String fileName = tempFile.getName()   

第二种:

fName = fName.trim()

fileName = fName.substring(fName.lastIndexOf("/")+1)

或者

fileName = fName.substring(fName.lastIndexOf("\\")+1)

第三种:

fName = fName.trim()

String temp[] = fName.split("\\\\")//split里面必须是正则表达式,宴氏哗"\\"的作用是对字符串转义,其中split("\\\\")的作用是:按照"\\"为分隔符,将路径核碰截取,并存入数组,如下:temp[]=[,D:,java,workspace,netmanager01,resources,mibfiles,wtView.mib]

fileName = temp[temp.length-1](取出最后一个)

<input type="file" 李晌告name="pic"谨启 accept="image/gif" multiple/>

加一个multiple关键字就能选择多个文件哪明


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/tougao/12239361.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-22
下一篇 2023-05-22

发表评论

登录后才能评论

评论列表(0条)

保存