首页 文章

如何在<form>中发送输入字段?

提问于
浏览
6

与我的last question有关 . 我有一个上传字段,用户可以选择一张图片,然后调整大小(客户端通过JavaScript),base64编码(也是JavaScript)并通过隐藏字段发送 . 我这样做是为了节省用户的带宽(例如使用3G连接) .

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

4 回答

  • 11

    您可以使用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;
        });
    });
    
  • 8

    只需删除 name="file" 属性即可 .

  • 2

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

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

    您可以在js-script中设置此属性...

  • 0

    我需要表单和输入才能有 name tag 所以我要做的就是在我的表单上设置一个 method tag . 这样,我的输入可以启用并具有标签名称 .

    <form name="form" method="post">
    

相关问题