const serialize = function (formEle) {
const fields = [].slice.call(formEle.elements, 0);
return fields
.map(function (ele) {
const name = ele.name;
const type = ele.type;
if (!name || ele.disabled || type === 'file' || (/(checkbox|radio)/.test(type) && !ele.checked)) {
return '';
}
if (type === 'select-multiple') {
return ele.options
.map(function (opt) {
return opt.selected ? `${encodeURIComponent(name)}=${encodeURIComponent(opt.value)}` : '';
})
.filter(function (item) {
return item;
})
.join('&');
}
return `${encodeURIComponent(name)}=${encodeURIComponent(ele.value)}`;
})
.filter(function (item) {
return item;
})
.join('&');
};