Kur*_*urt 9 html javascript forms jquery
关于我的上一个问题.我有一个上传字段,用户可以选择一张图片,然后调整大小(客户端通过JavaScript),base64编码(也是JavaScript)并通过隐藏字段发送.我这样做是为了节省用户的带宽(例如使用3G连接).
但我不知道如何不在标签<input type="file" name="file" id="file" class="span4">内发送用户上传文件<form>.显而易见的解决方案是从表单中排除文件上载字段,但这会杀死我的布局.这可能吗?
Cᴏʀ*_*ᴏʀʏ 10
您可以使用jQuery执行以下操作来禁用输入字段:
$('#file').prop('disabled', true);
Run Code Online (Sandbox Code Playgroud)
总而言之,你可能会这样:
// 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;
});
});
Run Code Online (Sandbox Code Playgroud)