Forms Jquery表单插件:如何仅在表单有enctype标记时显示进度条
我使用Jquery表单插件通过Ajax提交数据,我没有问题。 我还成功地实现了进度条 我希望仅当表单具有标记enctype=multipart/form data时才显示进度条,但我在读取AjaxForm对象中的表单属性时遇到问题:Forms Jquery表单插件:如何仅在表单有enctype标记时显示进度条,forms,jquery-plugins,Forms,Jquery Plugins,我使用Jquery表单插件通过Ajax提交数据,我没有问题。 我还成功地实现了进度条 我希望仅当表单具有标记enctype=multipart/form data时才显示进度条,但我在读取AjaxForm对象中的表单属性时遇到问题: $('.form_to_main').ajaxForm({ delegation: true, target: '#main_content', beforeSend: function(arr, myform, options) {
$('.form_to_main').ajaxForm({
delegation: true,
target: '#main_content',
beforeSend: function(arr, myform, options) {
_is_loading = true;
$('#loading').fadeIn();
//here something like if($(myform).attr("enctype") != '')
$('#loading .progress_bar .bar_container .bar').width('0%')
$('#loading .progress_bar .percent').html('0%');
//else $('#loading .progress_bar).hide();
},
beforeSubmit: function() {
if (_is_loading) return false;
},
uploadProgress: function(event, position, total, percentComplete) {
$('#loading .progress_bar .bar_container .bar').width(percentComplete + '%')
$('#loading .progress_bar .percent').html(percentComplete + '%');
},
error: function(xhr) {
BoxErrorShow('Connection error: ' + xhr.status + ' ' + xhr.statusText);
$('#loading').hide();
_is_loading = false;
},
success: function() {
$('#loading .progress_bar .bar_container .bar').width('100%')
$('#loading .progress_bar .percent').html('100%');
$('#loading').hide();
_is_loading = false;
}
});
});
在beforeSend:方法中,我想检查enctype属性,但我不清楚如何访问表单对象
谢谢你的支持
更新-已解决
我在beforeSend函数中使用beforeSubmit参数。
因此,正确的代码如下所示:
$('.form_to_main').ajaxForm({
delegation: true,
target: '#main_content',
beforeSend: function() {
_is_loading = true;
$('#loading').fadeIn();
$('#loading .progress_bar .bar_container .bar').width('0%')
$('#loading .progress_bar .percent').html('0%');
},
beforeSubmit: function(arr, myform, options) {
if ($(myform).attr("enctype") == 'multipart/form-data') $('#loading .progress_bar').show();
if (_is_loading) return false;
},
uploadProgress: function(event, position, total, percentComplete) {
$('#loading .progress_bar .bar_container .bar').width(percentComplete + '%')
$('#loading .progress_bar .percent').html(percentComplete + '%');
},
error: function(xhr) {
BoxErrorShow('Connection error: ' + xhr.status + ' ' + xhr.statusText);
$('#loading').hide();
_is_loading = false;
},
success: function() {
$('#loading .progress_bar .bar_container .bar').width('100%')
$('#loading .progress_bar .percent').html('100%');
$('#loading .progress_bar').hide();
$('#loading').hide();
_is_loading = false;
}
});
});
解决了我在beforeSend函数中使用beforeSubmit参数的问题。 有关详细信息,请参见答案