Jquery构建Form表单Post提交数据的简单方法

时间:2020-12-04 20:31:49
$.extend({
PostSubmitForm: function (url, args) {
var body = $(document.body),
form = $("<form method='post' style='display:none'></form>"),
input;
form.attr({ "action": url });
$.each(args, function (key, value) {
input = $("<input type='hidden'>");
input.attr({ "name": key });
input.val(value);
form.append(input);
}); //IE低版本和火狐下
form.appendTo(document.body);
form.submit();
document.body.removeChild(form[0]);
}
}); //示例
$.PostSubmitForm('url', { data1:'1',data2:'2' })