jquery serialize表单序列化,当radio或checkbox 未选中时,没有序列化到对

2020-07-11 18:07 2023-12-04 15:15 标签:jquery

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • //为jquery.serializeArray()解决radio,checkbox未选中时没有序列化的问题
  •     $.fn.ghostsf_serialize = function ({
  •         var a = this.serializeArray();
  •         var $radio = $('input[type=radio],input[type=checkbox]'this);
  •         var temp = {};
  •         $.each($radio, function ({
  •             if (!temp.hasOwnProperty(this.name)) {
  •                 if ($("input[name='" + this.name + "']:checked").length == 0) {
  •                     temp[this.name] = "";
  •                     a.push({namethis.name, value""});
  •                 }
  •             }
  •         });
  •         //console.log(a);
  •         return jQuery.param(a);
  •     };


怎么使用呢?引入即可  

  • 1
  • $(form).ghostsf_serialize()


压缩解压