Jquery 按特定顺序序列化

Jquery 按特定顺序序列化,jquery,serialization,Jquery,Serialization,我正在尝试以特定顺序序列化表单中的复选框值。 变量必须遵循字母顺序。只要遵守变量顺序,值顺序就无关紧要 这是html表单: <form> <input type="checkbox" value="value1"/> <input type="checkbox" value="value2"/> <input type="checkbox" value="value3"/> <input type="chec

我正在尝试以特定顺序序列化表单中的复选框值。 变量必须遵循字母顺序。只要遵守变量顺序,值顺序就无关紧要

这是html表单:

<form>
    <input type="checkbox" value="value1"/>
    <input type="checkbox" value="value2"/>
    <input type="checkbox" value="value3"/>
    <input type="checkbox" value="value4"/>
    <input type="checkbox" value="value5"/>
    <input type="checkbox" value="value6"/>
    <input type="checkbox" value="value7"/>
    <input type="checkbox" value="value8"/>
    <input type="checkbox" value="value9"/>
    <input type="checkbox" value="value10"/>
</form>
<p id="results"></p>​
我不想要的是:

b=valueX  or...
b=valueX&a=valueX  or...
a=valueX&c=valueX  or...
b=valueX&a=valueX&c=valueX&d=valueX&e=valueX
我希望你能理解我在找什么。任何帮助都将被感激


注意:尝试随机检查和取消检查输入,以确保代码按预期工作。

如果我已经很好地理解了问题,请告诉我:

$(document).ready(function(){
    $("input:checkbox").change(function(){
        var $checked = $(":checked");
        if( $checked.length > 5 ) {
            $(this).removeAttr("checked");
            return;
        }
        $checked.siblings()
            .andSelf().removeAttr("name");
        $checked.each( function(i, o) {
            $(this).attr("name", String.fromCharCode(97+i));
        });
        showValues();
    });

    function showValues() {
      str = $("form").serialize();
      $("#results").text(str);
    }
    /*$(":checkbox").click(showValues);
    $("select").change(showValues);*/
    showValues();
});​

b=valueX  or...
b=valueX&a=valueX  or...
a=valueX&c=valueX  or...
b=valueX&a=valueX&c=valueX&d=valueX&e=valueX
$(document).ready(function(){
    $("input:checkbox").change(function(){
        var $checked = $(":checked");
        if( $checked.length > 5 ) {
            $(this).removeAttr("checked");
            return;
        }
        $checked.siblings()
            .andSelf().removeAttr("name");
        $checked.each( function(i, o) {
            $(this).attr("name", String.fromCharCode(97+i));
        });
        showValues();
    });

    function showValues() {
      str = $("form").serialize();
      $("#results").text(str);
    }
    /*$(":checkbox").click(showValues);
    $("select").change(showValues);*/
    showValues();
});​