jQuery-在提交时添加其他参数(非ajax)

使用jQuery的“提交”-是否可以将其他参数传递给表单?我不希望使用Ajax进行此操作-这是正常的,刷新式的表单提交。


$('#submit').click(function () {

    $('#event').submit(function () {

        data: { 

        form['attendees'] = $('#attendance').sortable('toArray').toString();

    });

});


噜噜哒
浏览 1019回答 3
3回答

杨__羊羊

在您的情况下,只需将另一个隐藏字段动态添加到表单中就足够了。var input = $("<input>").attr("type", "hidden").val("Bla");$('#form').append($(input));

鸿蒙传说

您无需单击提交按钮就绑定提交事件,只需绑定提交事件即可,它将捕获提交事件,而不会触发它。想想您想要的是像通过ajax一样提交可排序对象。尝试做这样的事情:var form = $('#event').submit(function () {&nbsp; &nbsp; $.each($('#attendance').sortable('toArray'),function(i, value){&nbsp; &nbsp; &nbsp; &nbsp; $("<input>").attr({&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 'type':'hidden',&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 'name':'attendace['+i+']'&nbsp; &nbsp; &nbsp; &nbsp; }).val(value).appendTo(form);&nbsp; &nbsp; });});
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

JQuery