`

前台转 json

 
阅读更多

var fname = $("#saveBuy #firstname").val();  //saveBuy  from id

var lname = $("#saveBuy #lastname").val();

 

function getPostJson(id){

var json = {};

 

$(id).find("input[type$='text']").each(function(i){

   json[this.name]=this.value.replace(/(^\s*)|(\s*$)/g,"");

 });

$(id).find("input[type$='hidden']").each(function(i){

   json[this.name]=this.value.replace(/(^\s*)|(\s*$)/g,"");

 });

$(id).find("input[type$='radio']").each(function(i){

   if(this.checked)json[this.name]=this.value;

 });

$(id).find("input[type$='password']").each(function(i){

   json[this.name]=this.value.replace(/(^\s*)|(\s*$)/g,"");

 });

$(id).find("input[type$='checkbox']").each(function(i){

if(this.checked)json[this.name]=this.value;

 });

$(id).find("textarea").each(function(i){

   json[this.name]=this.value.replace(/(^\s*)|(\s*$)/g,"");

 });

$(id).find("select").each(function(i){

   json[this.name]=this.value;

 });

return json;

};

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics