Jquery把獲取到的input值轉(zhuǎn)換成json
更新時(shí)間:2017年05月15日 09:39:18 作者:yangzailu1990
本篇文章主要介紹了Jquery把獲取到的input值轉(zhuǎn)換成json的相關(guān)知識(shí),具有很好的參考價(jià)值。下面跟著小編一起來看下吧
話不多說,請(qǐng)看代碼:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title> jquery把獲取到的input值轉(zhuǎn)換成json</title> <meta http-equiv="Content-Type" content="text/html;charset=UTF-8" /> <link rel="stylesheet" type="text/css" href="" /> <style type="text/css"> .box{width:500px;height:500px;border:1px solid #e5e5e5;} </style> <script type="text/javascript" src="jquery-1.7.1.min.js"></script> </head> <body> <div class="box"> 姓名:<input type="text" value="" name="username" /> <br/><br/> 年齡:<input type="text" value="" name="age" /> <br/><br/> 生日:<input type="text" value="" name="birth" /> <br/><br/> 城市:<input type="text" value="" name="city" /> <br/><br/> 省份:<input type="text" value="" name="provicen" /> <br/><br/> 性別:<input type="text" value="" name="sex" /> <br/><br/> <input type="button" value="提交" class="comment"> </div> <script type="text/javascript"> $(document).ready(function(){ $(".comment").click(function(){ parArr = {}; var username = $('input[name=username]').val().replace(/(^\s*)|(\s*$)/g, ""); parArr.username = username; var age = $('input[name=age]').val().replace(/(^\s*)|(\s*$)/g, ""); parArr.age = age; var birth = $('input[name=birth]').val().replace(/(^\s*)|(\s*$)/g, ""); parArr.birth = birth; var city = $('input[name=city]').val().replace(/(^\s*)|(\s*$)/g, ""); parArr.city = city; var provicen = $('input[name=provicen]').val().replace(/(^\s*)|(\s*$)/g, ""); parArr.provicen = provicen; var sex = $('input[name=sex]').val().replace(/(^\s*)|(\s*$)/g, ""); parArr.sex = sex; var params = JSON.stringify(parArr); alert(params); }); }); </script> </body> </html>
以上就是本文的全部內(nèi)容,希望本文的內(nèi)容對(duì)大家的學(xué)習(xí)或者工作能帶來一定的幫助,同時(shí)也希望多多支持腳本之家!
相關(guān)文章
HTML 自動(dòng)伸縮的表格Table js實(shí)現(xiàn)
在開發(fā)的過程中,表格Table有個(gè)缺陷,如果一行中某個(gè)單元格的超過一行,表格就不夠美觀了。2009-04-04javascript實(shí)現(xiàn)點(diǎn)擊小圖顯示大圖
這篇文章主要為大家詳細(xì)介紹了javascript實(shí)現(xiàn)點(diǎn)擊小圖顯示大圖,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2020-11-11微信JS-SDK坐標(biāo)位置如何轉(zhuǎn)換為百度地圖坐標(biāo)
這篇文章主要介紹了微信JS-SDK坐標(biāo)位置如何轉(zhuǎn)換為百度地圖坐標(biāo) 的相關(guān)資料,感興趣的小伙伴們可以參考一下2016-07-07微信小程序scroll-view指定滾動(dòng)元素起始位置怎么做
scroll-view為滾動(dòng)視圖,分為水平滾動(dòng)和垂直滾動(dòng),這篇文章主要給大家介紹了關(guān)于微信小程序scroll-view不能左右滑動(dòng)問題的解決方法,需要的朋友可以參考下2022-12-12根據(jù)表格中的某一列進(jìn)行排序的javascript代碼
根據(jù)表格中的某一列進(jìn)行排序的實(shí)現(xiàn)方法有很多,下面為大家介紹下如何使用js來簡(jiǎn)單實(shí)現(xiàn)下,需要的朋友不要錯(cuò)過2013-11-11Javascript操縱Cookie實(shí)現(xiàn)購物車程序
Javascript操縱Cookie實(shí)現(xiàn)購物車程序...2006-11-11