[英]How to not send an input field in a <form>?
关于我的上一个问题 。 我有一个上传字段,用户可以选择一张图片,然后调整大小(客户端通过JavaScript),base64编码(也是JavaScript)并通过隐藏字段发送。 我这样做是为了节省用户的带宽(例如使用3G连接)。
但我不知道如何不在<form>
标签内发送用户上传文件<input type="file" name="file" id="file" class="span4">
。 显而易见的解决方案是从表单中排除文件上载字段,但这会杀死我的布局。 这可能吗?
只需删除name="file"
属性即可。
您可以使用jQuery执行以下操作来禁用输入字段:
$('#file').prop('disabled', true);
总而言之,你可能会这样:
// domReady handler
$(function() {
// provide an event for when the form is submitted
$('#myform').submit(function() {
// Find the input with id "file" in the context of
// the form (hence the second "this" parameter) and
// set it to be disabled
$('#file', this).prop('disabled', true);
// return true to allow the form to submit
return true;
});
});
如果您可以将“已禁用”属性添加到输入中,则不会将其与表单一起提交:
<input type="file" name="file" id="file" class="span4" disabled="disabled">
您可以在js-script中设置此属性...
我需要表单和输入有一个名称标签所以我要做的是在我的表单上设置方法标记 。 这样,我的输入可以启用并具有标签名称。
<form name="form" method="post">
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.