Jquery的序列化方法为什么要把空格替换成加号呢?
param: function( a ) {
var s = [ ];
function add( key, value ){
s[ s.length ] = encodeURIComponent(key) + '=' + encodeURIComponent(value);
};
// If an array was passed in, assume that it is an array
// of form elements
if ( jQuery.isArray(a) || a.jquery )
// Serialize the form elements
jQuery.each( a, function(){
add( this.name, this.value );
});
// Otherwise, assume that it's an object of key/value pairs
else
// Serialize the key/values
for ( var j in a )
// If the value is an array then the key names need to be repeated
if ( jQuery.isArray(a[j]) )
jQuery.each( a[j], function(){
add( j, this );
});
else
add( j, jQuery.isFunction(a[j]) ? a[j]() : a[j] );
// Return the resulting serialization
return s.join("&").replace(/%20/g, "+");
}
为什么要替换下呢,为什么要替换成加号呢?return s.join("&").replace(/%20/g, "+");
如果用户在输入框中输入了空格的字符串;我用JQuery的序列化方法得到URL串然后提交的方式,就会造成后台数据的不正确,不知道有没有好的办法?
...全文
相关推荐
使用Post提交时须将空格转换成加号的解释
参数有中包含空格且使用Post提交时须将空格转换成加号,这样后台程序接受到的才是真正的空格,感兴趣的朋友可以了解下
jquery选择器中的空格与大于号、加号+与波浪号~的区别介绍
概念 空格:$(‘parent childchild’)表示获取parent下的所有的childchild节点 大于号:$(‘parent > childchild’)表示获取parent下的所有下一级childchild 加号:$(‘pre + nextbrother’)表示获得pre节点的下一个兄弟节点,相当于next()方法 波浪号:$(‘pre ~ brother’)表示获取pre节点的后面的所有兄弟节点,相当于nextAll()方法 详解描述 现有代码如下 <meta charset="utf-8"> <script type="text/javascript" src="js/j
jquery选择器中的空格与大于号>、加号+与波浪号~的区别介绍
主要介绍了jquery选择器中的空格与大于号>、加号+与波浪号~的区别介绍的相关资料,需要的朋友可以参考下
Jquery-validate扩展方法(验证空格)
jquery-validate 可对前端form进行表单校验,文档里详细介绍了如何使用jquery-validate框架和如何扩展验证方法。
JQuery点击弹出与收回事件(加号变减号)
NULL 博文链接:https://turbo12138.iteye.com/blog/2308186


