$.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' })