jQuery-在提交时添加其他参数(非ajax) [英] jQuery - add additional parameters on submit (NOT ajax)

查看:76
本文介绍了jQuery-在提交时添加其他参数(非ajax)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

Using jQuery's 'submit' - is there a way to pass additional parameters to a form? I am NOT looking to do this with Ajax - this is normal, refresh-typical form submission.

$('#submit').click(function () {
    $('#event').submit(function () {
        data: { 
        form['attendees'] = $('#attendance').sortable('toArray').toString();
    });
});

推荐答案

这个为我做了:

var input = $("<input>")
               .attr("type", "hidden")
               .attr("name", "mydata").val("bla");
$('#form1').append(input);

基于Daff的答案,但添加了NAME属性以使其显示在表单集合中,并将VALUE更改为VAL 还检查了FORM的ID(在我的情况下为form1)

is based on the Daff's answer, but added the NAME attribute to let it show in the form collection and changed VALUE to VAL Also checked the ID of the FORM (form1 in my case)

使用Firefox萤火虫检查元素是否已插入.

used the Firefox firebug to check whether the element was inserted.

隐藏的元素确实会回发到表单集合中,仅保留只读字段.

Hidden elements do get posted back in the form collection, only read-only fields are discarded.

米歇尔

这篇关于jQuery-在提交时添加其他参数(非ajax)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆