我使用tag <input type="file" accept="application/x-rpt, magnus-internal/rpt"/>只允许上传.rpt文件,但不成功。用户仍然可以上传任何他们想要的东西。
这是怎么回事?请帮帮我。非常感谢。
发布于 2013-09-02 18:01:41
将以下脚本放入head中
<script type="text/javascript">
function ValidateForm() {
var fileBox = document.getElementById("fileBox");
var val = fileBox.value;
var splittedValue = val.split(".");
//alert(splittedValue.length);
//for (var i = 0; i < splittedValue.length; i++) {
// alert(splittedValue[i]);
//}
var NthElementIndex = splittedValue.length - 1;
var nThElement = splittedValue[NthElementIndex];
if (nThElement != "jpg"
&& nThElement != "rpt") {
alert("Please select valid rpt file");
}
}
</script>现在对输入标记中的id使用以下信息
<input type="file" id="fileBox" />
<input type="button" onclick="ValidateForm()" value="Validate" />https://stackoverflow.com/questions/18568241
复制相似问题