与我的last question有关。我有一个上传字段,用户可以选择一张图片,然后调整大小(客户端通过JavaScript),base64编码(也是JavaScript)并通过隐藏字段发送。我这样做是为了节省用户的带宽(例如使用3G连接)。
但我不知道如何在<input type="file" name="file" id="file" class="span4">
代码中不发送用户上传文件<form>
。显而易见的解决方案是从表单中排除文件上载字段,但这会杀死我的布局。这可能吗?
答案 0 :(得分:12)
只需删除name="file"
属性。
答案 1 :(得分:8)
您可以使用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;
});
});
答案 2 :(得分:2)
如果您可以将“禁用”属性添加到输入中,则不会将其与表单一起提交:
<input type="file" name="file" id="file" class="span4" disabled="disabled">
您可以在js-script中设置此属性...
答案 3 :(得分:0)
我需要表单和输入才能有名称标签所以我要做的就是在表单上设置方法标记。这样,我的输入可以启用并具有标记名称。
<form name="form" method="post">