怎么用javascript验证Form表单的file元素

1.判断是否为空
2.判断路径是否正确

判断是否为空
var str=Trim(document.forms[0].filename.value);
if(fucCheckLength(str) == 0){
alert("file路径为空!");
}
我没明白你的“路径是否正确”什么意思,不过只要能获得路径字符串,想怎么处理怎么处理。
温馨提示:答案为网友推荐,仅供参考
第1个回答  推荐于2016-01-30
<body>
<form action="" method="post" onsubmit="return check();">
<input id="File1" type="file" /><br />
<input id="Submit1" type="submit" value="submit" />
</form>
</body>
</html>
<script type="text/javascript">
function check(){
if(document.getElementById("File1").value.length==0){
alert("不能为空");
return false;
}
if(document.getElementById("File1").value.toLowerCase() != "d:\1.txt"){
alert("路径不正确"+document.getElementById("File1").value.toLowerCase());
return false;
}
}
</script>本回答被提问者采纳

相关了解……

你可能感兴趣的内容

本站内容来自于网友发表,不代表本站立场,仅表示其个人看法,不对其真实性、正确性、有效性作任何的担保
相关事宜请发邮件给我们
© 非常风气网