jQuery序列化将所有空格转换为加号

编程入门 行业动态 更新时间:2024-10-11 07:33:16
本文介绍了jQuery序列化将所有空格转换为加号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

当前,在所有我要使用序列化的地方,我都必须像这样使用它:

Currently, everywhere I use serialize I have to use it like this:

.serialize().replace(/\+/g,'%20');

否则,表单数据中的任何空格都将被加为+.是否有可以将其设置为默认值的设置.

otherwise any spaces in the form data will be coverted to +'s. Is there a setting that can make this the default.

推荐答案

有趣的是,这是一种不使用临时变量的替代方法:

For fun, here's an alternative that doesn't use a temporary variable:

$.fn.serializeAndEncode = function() { return $.map(this.serializeArray(), function(val) { return [val.name, encodeURIComponent(val.value)].join('='); }).join('&'); }; $("#formToSerialize").serializeAndEncode();

更多推荐

jQuery序列化将所有空格转换为加号

本文发布于:2023-07-14 20:09:13,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1106725.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:加号   空格   转换为   序列化   jQuery

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!