0

配列構文を理解するのに苦労しています。6 セットのチェックボックスがあり、理想的には、このフォーム フルフィルメントの反対側で解析するために、応答 (オン = 1 またはオフ = 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>

JQuery サンプル:

    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);
}

ありがとうございました!

4

0 に答える 0