【发布时间】:2014-11-22 14:11:49
【问题描述】:
如果上传文件格式有效,我需要按下“提交”按钮。我已经设法使用下面的 JavaScript 检查格式。我的目标是介于 // 和 // ...
<script>
function Checkfiles(f){
f = f.elements;
if(/.*\.(gif)|(jpeg)|(jpg)|(doc)$/.test(f['filename'].value.toLowerCase()))
return true; + // and press the button submit //
alert('Please Upload Gif or Jpg Images, or Doc Files Only.');
f['filename'].focus();
return false;
};
</script>
这是 HTML 表单:
<form action="something.php" method="post" name="myForm" onsubmit="return Checkfiles(this);">
<input type="file" name="filename" accept="/image*/">
<input type="submit" name="submit">
</form>
谢谢。
【问题讨论】:
-
鉴于您的函数是从表单的
onsubmit调用的,您认为以编程方式按下提交按钮会有什么效果?请从用户的角度描述您想要实现的目标。 -
返回
true提交表单,为什么需要触发点击该函数内的提交按钮? -
Java 不是 Javascript。
标签: javascript jquery html forms