Turn a form into an associative array in Jquery

This question already has an answer here:

  • Convert form data to JavaScript object with jQuery 50 answers

  • Here's a dead-simple way:

    $.fn.form = function() {
        var formData = {};
        this.find('[name]').each(function() {
            formData[this.name] = this.value;  
        })
        return formData;
    };
    
    // use like
    var data = $('#editForm').form();
    

    This is totally unsafe and just grabs everything with a name, but it should get you started.

    链接地址: http://www.djcxy.com/p/46332.html

    上一篇: 从Javascript动态构建JSON对象列表

    下一篇: 在Jquery中将表单转换为关联数组