Home > Web Front-end > JS Tutorial > body text

jQuery.query.js 取参数的两点问题分析_jquery

WBOY
Release: 2016-05-16 17:51:12
Original
770 people have browsed it

1. 参数中存在空格时取到的值中空格被替换为加号:+
2. 当参数某个key的value不存在时,获取到的value并不是空/null 而是true。

在网上找到了个解决方案,可以参考下(是否有其他副作用暂时未实验出)

1. 空格变加号+

在jQuery.query.js文件中找到下面代码

复制代码 代码如下:

toString: function() {
var i = 0, queryString = [], chunks = [], self = this;
var encode = function(str) {
str = str + "";
//if ($spaces) str = str.replace(/ /g, "+");
return encodeURIComponent(str);
};


注释掉 if ($spaces) str = str.replace(/ /g, "+"); 那一行即可

2. value为空的情况
复制代码 代码如下:

get: function (key)
{
var target = this.GET(key);
if (typeof (target) == 'boolean')
return '';
if (is(target, Object))
return jQuery.extend(true, {}, target);
else if (is(target, Array))
return target.slice(0);
return target;
},

加入if (typeof (target) == 'boolean')return '';
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!