我正在尝试创建一个 jQuery 插件,它将表单克隆到 iframe 然后提交表单。伪造ajax文件上传是一种黑客行为。我也知道已经有这样的插件,但我没有尝试满足我的需求。我在将 jQuery 对象附加到 IE 中的任何内容时遇到问题。(我正在运行 IE 7.0)我已经尝试过 FF,它运行良好。我也在使用 jQuery 1.3.2 分钟。任何帮助将不胜感激。
(function($){
$.fn.extend({
//pass the options variable to the function
formUploader: function(options) {
//Set the default values, use comma to separate the settings, example:
var defaults = {
onSubmit: function(){ return true;},
onComplete: function(){ return true;}
}
var settings = $.extend(defaults, options);
return this.each(function() {
$(this).submit(function(){
var id = "asdfasda";
$(document).find('body').append('<iframe src="javascript:false;" name="' + id + '" id="' + id + '" />');
//this should be a form
var curEl = this;
setTimeout(function()
{
//fails in IE but not in FF
$("#"+id).contents().find("body").append($(curEl).clone());
},250);
return false;
});
});
}
});
})(jQuery);