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

html-css06

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](取出最后一个)

一.准备HTML文件及其资源文件

使用UIWebView加载本地的HTML4文件 index.html,在index.html中引用了本地的图片、CSS文件、JS文件以及外部的图片。

二.加载本地HTML文件

将html5文件及相关资源添加到项目中,调用需要上传的文件夹。

三.选择调用的文件夹上传。