<html> <head> <meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>文件上载</title>
<script>
//可以上传的文件类形
function filetype(){
var sTheFile = document.forms[0].pic.value;
var filename = document.forms[0].filename;
var sFileName = sTheFile.substring(sTheFile.lastIndexOf("\\") + 1);
var Name=sFileName.substring(sFileName.indexOf(".")+1).toLowerCase();
var ext = new Array('jpg','jpeg','png','gif','bmp','ico');
for (var i=0 ;i<ext.length; i++){
if( Name == ext[i]){
filename.value = sFileName;
//alert(filename.value)
return true;
}
}
alert("上传文件格式不正确!");
document.getElementById("div1").innerHTML='<input type="file" name="pic" id="pic" value="" onChange="filetype()">'
return false;
}
//验证表单
function checkValue(){
var sJbr = document.forms[0].jbr.value;
var sSelect = document.forms[0].select.options(document.forms[0].select.selectedIndex).value;
var sContent = document.forms[0].content.value;
var sTheFile = document.forms[0].pic.value;
if (sJbr =="" ||sJbr == null){
alert("请填写举报人!");
return false;
}
if (sSelect =="" ||sSelect == null){
alert("请选择分局!");
return false;
}
if (sContent =="" ||sContent == null){
alert("请填写缺陷!");
return false;
}
if (sTheFile =="" ||sTheFile == null){
alert("缺陷截图不能为空!");
return false;
}
}
</script>
</head>
<body>
<form action="/report/servlet/BugFeed" onSubmit="return checkValue()" enctype="MULTIPART/FORM-DATA" method=post>
<p>举报人:
<input type="text" name="jbr" onBlur="checkValue()">
</p>
<p>分局:
<select name="select">
<option value="">请选择分局</option>
<option value="城东局">城东局</option>
<option value="城南局">城南局</option>
<option value="城西局">城西局</option>
<option value="城北局">城北局</option>
<option value="其它">其它</option>
</select>
</p>
<p>描述缺陷:
<textarea name="content"></textarea>
</p>
<p>选择要上载的图片:
<div id="div1"><input type="file" name="pic" id="pic" value="" onChange="filetype()"></div>
</p>
<input type="hidden" value="" name="filename" id="filename">
<p>
<input type=submit value="Upload">
</p>
</form>
</body>
</html>