html tag code in asp.net:
The code copy is as follows:
<asp:FileUpload ID="fuMain" runat="server" />
<asp:Button ID="btnUpload" runat="server" OnClientClick="return CheckWorkFile()" Text="Upload" />
Ordinary html tags:
The code copy is as follows:
<input type="file" ID="fuMain" />
<input type="button" ID="btnUpload" onclick="return CheckWorkFile()" Text="upload" />
For ASP.NET or plain HTML tags, the following JS code applies:
The code copy is as follows:
function CheckWorkFile()
{
var obj=document.getElementById('fuMain');
if(obj.value=='')
{
alert('Please select the homework file to upload');
return false;
}
var stuff=obj.value.match(/^(.*)(/.)(.{1,8})$/)[3];
if(stuff!='doc')
{
alert('File type is incorrect, please select .doc file');
return false;
}
return true;
}