javascript - 如何在表单提交时不上传图像/文件

标签 javascript jquery html post submit

我有简单的表单,想在按下主提交按钮后上传图像,但在按下后退按钮后不上传图像?有任何想法吗?请注意 BACK 正在对表单执行不同的操作。

 <form method="post" name="Form" id="Form" action="upload.php" enctype="multipart/form-data">

    <input  class="button_date" id="fileInputBox" style="margin-bottom: 5px;" type="file" name="file[]" extension="jpeg|jpg|png|gif|giff|tiff" required/>

    <input class="button2 cancel" style="border-right:none; font-size:13px;" name="Back" id="Back" type="submit"  value="Back" onClick="javascript: form.action='back.php';"/>

    <input class="button2" style="border-right:none; font-size:13px;" name="List Item" id="submit" type="submit" value="List Item" onClick="removeFocus()"/>

 </form>

最佳答案

如果禁用输入,则不会提交该输入,请参阅此处了解更多详细信息 values of disabled inputs will not be submited?

所以添加:

document.getElementById('fileInputBox').disabled = true;

<input class="button2 cancel" style="border-right:none; font-size:13px;" name="Back" 
    id="Back" type="submit"  value="Back" 
    onClick="javascript:document.getElementById('fileInputBox').disabled = true; 
    form.action='back.php';"/>

关于javascript - 如何在表单提交时不上传图像/文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17968462/

相关文章:

jquery - 为多列应用唯一类

javascript - Shadow DOM 与分离元素

HTML 表单 : Radio buttons with text fields

javascript - 如何订购 ng-repeat 商品?

javascript - 我怎样才能清理这个 jQuery 代码?

javascript - 使用 jQuery 在点显示图像

javascript - 找到 HTML 元素和浏览器(或窗口)边之间的距离

javascript - 右键单击 div 时未打开上下文菜单

javascript - Gatsby : Search based on markdown files

javascript - 为输出功能创建可搜索的下拉菜单