Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/arrays/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
jQuery保存复选框选中状态到查询字符串_Jquery_Arrays_Checkbox_Query String_Checked - Fatal编程技术网

jQuery保存复选框选中状态到查询字符串

jQuery保存复选框选中状态到查询字符串,jquery,arrays,checkbox,query-string,checked,Jquery,Arrays,Checkbox,Query String,Checked,我正在努力理解数组语法。我有6组复选框,理想情况下,我希望能够将响应(checked on=1或off=0)发送到查询字符串中,以便在此表单的另一端进行解析 到目前为止,我已经包含了我所拥有的内容,并且它是有效的,但是我更希望我的URL更短,并且更高效地到达那里 当前URL:http://domain/index.html?t1a=0&t1b=1&t2a=0&t2b0(想象一下这有30个参数) 目标URL:http://domain/index.html?t1=01&t2=00 HTML示例:

我正在努力理解数组语法。我有6组复选框,理想情况下,我希望能够将响应(checked on=1或off=0)发送到查询字符串中,以便在此表单的另一端进行解析

到目前为止,我已经包含了我所拥有的内容,并且它是有效的,但是我更希望我的URL更短,并且更高效地到达那里

当前URL:
http://domain/index.html?t1a=0&t1b=1&t2a=0&t2b0
(想象一下这有30个参数)

目标URL:
http://domain/index.html?t1=01&t2=00


HTML示例:

<form>
<div id="checkbox-topic1">
    <input name="topic1" class="interest-checkbox" id="topic1a" type="checkbox" />
    <input name="topic1" class="interest-checkbox" id="topic1b" type="checkbox" />
</div>
<div id="checkbox-topic2">
    <input name="topic2" class="interest-checkbox" id="topic2a" type="checkbox" />
    <input name="topic2" class="interest-checkbox" id="topic2b" type="checkbox" />
</div>
</form>

谢谢大家!

假设这些复选框以某种形式出现,您是否见过.serlize()方法?谢谢,这是一种非常有效的创建查询字符串的方法,类似于我已经拥有的,我理想情况下希望创建一个更短的查询字符串,因为我遇到了30个参数,只是好奇。。。为什么要连接查询字符串?带有POST的表单对您不起作用吗?该表单也会单独发布数据(很抱歉,我的缩写代码有误导性)。但是我正在使用自定义URL将用户重定向到自定义结果页面,并存储连接的结果,以发送到我们的销售CRM进行联系人跟进。
    function appendURLQueryString() {
    var customURL = $("#custom-url");
    // TOPIC 1 ================//
    var t1a = 0;
    if ($('#topic1a').is(':checked')) {
        t1a = 1;
    }
    var t1b = 0;
    if ($('#topic1b').is(':checked')) {
        t1b = 1;
    }
    // TOPIC 2 ================//
    var t2a = 0;
    if ($('#topic2a').is(':checked')) {
        t2a = 1;
    }
    var t2b = 0;
    if ($('#topic2b').is(':checked')) {
        t2b = 1;
    }
    var tempURL = ('http://domain/index.html?t1a=' + t1a + '&t1b=' + t1b + '&t2a=' + t2a + '&t2b=' + t2b);
    customURL.attr("value", tempURL);
}