如何使用JQUERY将提交的表单数据转换为json数组并将json数组存储到localstorage

时间:2018-07-31 18:35:33

标签: javascript jquery html html5 local-storage

如何使用JSONJSON将提交的表单数据转换成localstorage数组并将jQuery数组存储到Javascript中?以及如何在HTML页上打印输出数据?

<form>
   <label>Name</label>   
   <input id = "name" type = "text"/>
   <label>Title</label>   
   <input id = "title" type = "text"/>
   
   <label>Description</label>     
   <input id = "description" type = "text" rows="4" cols="50"/> 
   
   <label>New Comments</label>  
   <input id = "comments" type = "text" rows="4" cols="50"/> 
   
   <input type="radio" name = "icon"/> like 
   <input type="radio"  name = "icon" /> unlike 
   
   <button id = "save" value = "submit">Save</button>        
   <button id = "display" value = "submit">Display</button> 
</form>

1 个答案:

答案 0 :(得分:0)

来自jquery .serializeArray()

$( "form" ).submit(function( event ) {
   console.log( $( this ).serializeArray() );
   event.preventDefault();
});