这是来自的 html
<form action="http://localhost/own/import.php" method="post" enctype="multipart/form-data" name="form1">
<input type="file" name="xmlfile" id="file1">
<input type="file" name="uploaded_image" id="file2">
<input type="submit" id="submit" name="Submit" value="Submit" style="margin:0 0 0 150px;">
这是java脚本文件
function getExt(filename) {
var dot_pos = filename.lastIndexOf(".");
if (dot_pos == -1) {
return "";
}
return filename.substr(dot_pos + 1).toLowerCase();
}
function validate_ext() {
var filename = document.getElementById("file1").value;
var filename2 = document.getElementById("file2").value;
var ext = getExt(filename);
var ext2 = getExt(filename2);
if (filename != "") {
if (!(ext == "xml")) {
alert("Please upload XML file format only");
return false;
}
}
if (filename2 != "") {
if (!((ext2 == "jpg") || (ext2 == "jpeg") || (ext2 == "png"))) {
alert("Please upload jpg, jpeg, png file format only");
return false;
}
}
return true;
}
$(document).ready(function() {
$('#submit').click(validate_ext);
alert("test");
});
我也在这里分享代码http://jsfiddle.net/vikastyagi87/XugLp/18/
</p>