【请大家为我解决一个上传组件Fileupload的问题!】
我用.net自带的fileupload做上传,他是由一个文本框和一个按钮组成的吧,我现在想上传一个图片,选了以后,图片的扩展名就会显示在文本框里,现在要想在前台做判断,比如我乱上传一个.txt的进去,就提示“你上传的不是图片”
现在怎么去前台做判断,就是说如何在前台得到组件里文本框的值!:???
------解决方案--------------------简单写了一个,LZ 看下吧
<html xmlns= "http://www.w3.org/1999/xhtml " >
<head runat= "server ">
<title> Untitled Page </title>
<script language = "javascript " >
function Check()
{
alert(document.getElementById( "upload ").value);
}
</script>
</head>
<body>
<form id= "form1 " runat= "server ">
<div>
<asp:FileUpload ID= "upload " runat = "server " />
<asp:Button ID= "btn " OnClientClick = "Check(); " runat = "server " Text = "测试 " />
</div>
</form>
</body>
</html>
------解决方案--------------------function isPic(){
var ExtList = ".jpg.gif.bmp.png.swf ";
var filename = document.getElementById( "file1 ");
var the_ext = filename.substr(filename.lastIndexOf( ". ")+1).toLowerCase();
if (ExtList.indexOf(the_ext)==-1){
alert( "请选择规定范围的图片文件! ");
return false;
}
return true;
}
<input id= "file1 " type=file name= "filename ">
<input type=submit value= "上传 " onclick= "return isPic() ">