11

关于我的最后一个问题。我有一个上传字段,用户可以在其中选择一张图片,它会调整大小(通过 JavaScript 客户端),base64 编码(JavaScript 也是)并通过隐藏字段发送。我这样做是为了节省用户的带宽(例如使用 3G 连接)。

但我不知道如何不在标签<input type="file" name="file" id="file" class="span4">内发送用户上传文件。<form>显而易见的解决方案是从表单中排除文件上传字段,但这会破坏我的布局。这可能吗?

4

4 回答 4

22

只需删除name="file"属性。

于 2014-11-24T08:43:57.600 回答
13

您可以使用 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;
    });
});
于 2013-03-27T22:18:26.207 回答
3

如果您可以将属性“禁用”添加到输入,它将不会与表单一起提交:

<input type="file" name="file" id="file" class="span4" disabled="disabled">

您可以在 js 脚本中设置此属性...

于 2013-03-27T22:14:52.010 回答
0

我需要表单和输入有一个名称标签,所以我要做的就是在我的表单上设置一个方法标签。这样,我的输入可以启用并具有标签名称。

<form name="form" method="post">
于 2017-02-24T12:31:29.967 回答