封装json需要自行拼接。Google: javascript form to json 会有很多结果。
更长见的组织方式为getstring。详见jQuery的.serialize()方法。
$( "form" ).on( "submit", function( event ) {
event.preventDefault();
console.log( $( this ).serialize() );
});
e.g.
Single
Single2
Multiple
Multiple2
Multiple3
check1
check2
radio1
radio2
function showValues() {
var str = $( "form" ).serialize();
$( "#results" ).text( str );
}
$( "input[type='checkbox'], input[type='radio']" ).on( "click", showValues );
$( "select" ).on( "change", showValues );
showValues();
//Output
single=Single&multiple=Multiple&multiple=Multiple3&check=check2&radio=radio1