本文介绍了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序列化将所有空格转换为加号
发布评论