DIV CSS 佈局教程網

 DIV+CSS佈局教程網 >> 網頁腳本 >> JavaScript入門知識 >> jQuery入門知識 >> JQuery特效代碼 >> jQuery把表單元素變為json對象
jQuery把表單元素變為json對象
編輯:JQuery特效代碼     
. 代碼如下:
(function($){ 
$.fn.serializeObject=function(){ 
           var inputs=$(this).find("input,textarea,select"); 
           var o = {}; 
           $.each(inputs,function(i,n){ 
               switch(n.nodeName.toUpperCase()){ 
                   case "INPUT": 
                       if($(n).is(":checkbox")){ 
                           if($(n).is(":checked")){ 
                               o[n.name]=true; 
                           }else{ 
                               o[n.name]=false; 
                           } 
                       }else if($(n).is(":radio")){ 
                           if($(n).is(":checked")){ 
                               o[n.name]=n.value; 
                           } 
                       }else{ 
                           o[n.name]=n.value;  
                       } 

                       break; 
                   case "TEXTAREA": 
                       o[n.name]=$(n).text(); 
                       break; 
                   case "SELECT": 
                       o[n.name]=n.value; 
                       break; 
               } 
           }); 
           return o; 
       } 
})(jQuery);
XML學習教程| jQuery入門知識| AJAX入門| Dreamweaver教程| Fireworks入門知識| SEO技巧| SEO優化集錦|
Copyright © DIV+CSS佈局教程網 All Rights Reserved