日期:2014-05-16 浏览次数:20604 次
<html:file property="uploadFile" styleClass="upload" size ="40" onchange="checkFileExtension(this);"/>
<input type="file" id="file" onchange="checkFileExtension(this);" />
function checkFileExtension(file) { var validExtensions = new Array(".xlsx", ".xls"); var fileExtension = file.value; fileExtension = fileExtension.substring(fileExtension.lastIndexOf('.')); if (validExtensions.indexOf(fileExtension) < 0) { // Alert massage to user. alert("Only " + validExtensions.toString() + " types are allowed."); // Clean file info. file.value = ""; return false; } else { return true; } }