jQuery deserialize form

后端 未结 11 810
日久生厌
日久生厌 2020-12-13 09:21

I am using jQuery Serialize to serialize my form elements and would like to deserialize them back. Unfortunately can\'t find any working jQuery deserializer, any suggestions

11条回答
  •  悲哀的现实
    2020-12-13 09:42

    Needed all in a single string, which can be stored in maybe COOKIE, and later read and fill the same form with input values.

    Input elements seperator: ~ (use any seperator)

    Input attributes seperator: | (use any seperator)

    input type | input name | input value ~ input2 type | input2 name | input2 value

    var formData = '';
    $('#form_id').find('input, textarea, select').each(function(i, field) {
        formData += field.type+'|'+field.name+'|'+field.value+'~';
    });
    

    Example:

    hidden|vote_id|10~radio|option_id|~radio|option_id|427~radio|option_id|428~
    

提交回复
热议问题