是否可以让表单通过GET提交以逗号分隔的列表? [英] Is it possible to have a form submit a comma separated list via GET?

查看:71
本文介绍了是否可以让表单通过GET提交以逗号分隔的列表?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

比方说,我有一个表单,其中包含一堆具有相同名称c的复选框.每个复选框都有一个分配给它的整数值.

Let's say I have a form that contains a whole bunch of check boxes with the same name, c. Each checkbox has an integer value assigned to it.

通过GET提交表单后,我希望该网址看起来像www.url.com/?c=1,2,3,4,5

When the form is submitted, via GET, I'd like the url to look like www.url.com/?c=1,2,3,4,5

不是

www.url.com/?c=1&c=2&c=3&c=4&c=5

可能吗?还是我必须捕获通过jQuery提交的表单,遍历每个复选框并在我自己的url var上添加标签?

Possible? or will I have to capture the form submit via jQuery, loop through each checked box, and tack on my own url var?

推荐答案

您必须借助Javascript来完成此任务.

You'll have to resort to Javascript to accomplish this.

在jQuery中,这是您可能要做的事情:

In jQuery, this is how you might go about it:

$('form').submit(function()
{
    var values = [];

    $(this).find('input[type="checkbox"][name="c"]:checked').each(function()
    {
        values.push(this.value);
    });

    window.location = 'www.url.com/?c=' + values.join(',');
});

这篇关于是否可以让表单通过GET提交以逗号分隔的列表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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