<SCRIPT LANGUAGE="JavaScript">
<!--
// 去左空格
function ltrim(s){
return s.replace( /^\s*/, "");
}
// 去右空格
function rtrim(s){
return s.replace( /\s*$/, "");
}
// 去左右空格
function trim(s){
return rtrim(ltrim(s));
}
//获取文件扩展名
function get_ext(f_path){
var ext = '';
if(f_path != null && trim(f_path).length > 0){
f_path = trim(f_path);
ext = f_path.substring(f_path.lastIndexOf(".") + 1, f_path.length);
}
return ext;
}
//验证文件扩展名
function chk_ext(f_path){
var ext = get_ext(f_path);
//根据需求定制
var accept_ext = new Array("BMP","JPEG","GIF","PSD","PNG","TIFF","TGA","EPS","JPG");
var flag = false;
if(ext != ''){
for(var i=0; i<accept_ext.length; i++){
if(ext.toLowerCase() == accept_ext[i])
flag = true;
}
}
return flag;
}
//-->
</SCRIPT>
调用
<script type="text/javascript">
function dd(){
var name=document.getElementById("yzname");
if(name.value!=""){
if(!chk_ext(document.all.file1.value)){
alert("不支持此格式!");
return false;
}
document.form1.action="../../../upload?path=edu&actionClass=net.hlj.eduWork.myDocuments.seal.service.SealUploadAction";
document.form1.method="post";
document.form1.submit();
// alert("新增成功!");
}else{
alert("电子印章名称不能为空!添加失败!");
}
}
</script>