admin 管理员组文章数量: 1086019
I use this code from aweber that passes user information from signup to the next page, here is the code from aweber
<script type="text/javascript">
var formData = function(){
var query_string = (location.search)?((location.search.indexOf('#') != -1) ? location.search.substring(1, location.search.indexOf('#')) : location.search.substring(1)) : '';
var elements = [];
if(query_string){
var pairs = query_string.split("&");
for(i in pairs) {
if (typeof pairs[i] == 'string') {
var tmp = pairs[i].split("=");
var queryKey = unescape(tmp[0]);
queryKey = (queryKey.charAt(0) == 'c') ? queryKey.replace(/\s/g, "_") : queryKey;elements[queryKey] = unescape(tmp[1]);
}
}
}
return{display: function(key){if(elements[key]){document.write(elements[key]);
}else {
document.write("<!--If desired, replace everything between these quotes with a default in case there is no data in the query string.-->");
}}}}();
</script>
then this is the code on the page to display name
<script type="text/javascript">formData.display("fullname")</script>
The example output will be FirstName%20LastName
Is there a way that %20
will be removed?
I use this code from aweber that passes user information from signup to the next page, here is the code from aweber
<script type="text/javascript">
var formData = function(){
var query_string = (location.search)?((location.search.indexOf('#') != -1) ? location.search.substring(1, location.search.indexOf('#')) : location.search.substring(1)) : '';
var elements = [];
if(query_string){
var pairs = query_string.split("&");
for(i in pairs) {
if (typeof pairs[i] == 'string') {
var tmp = pairs[i].split("=");
var queryKey = unescape(tmp[0]);
queryKey = (queryKey.charAt(0) == 'c') ? queryKey.replace(/\s/g, "_") : queryKey;elements[queryKey] = unescape(tmp[1]);
}
}
}
return{display: function(key){if(elements[key]){document.write(elements[key]);
}else {
document.write("<!--If desired, replace everything between these quotes with a default in case there is no data in the query string.-->");
}}}}();
</script>
then this is the code on the page to display name
<script type="text/javascript">formData.display("fullname")</script>
The example output will be FirstName%20LastName
Is there a way that %20
will be removed?
3 Answers
Reset to default 6%20 is the symbol for whitespace in url encoding. For some reason your function returns url-encoded data. Try url decoding the output and your %20 should be represented as whitespace.
You can use decodeURI (http://www.w3schools./jsref/jsref_decodeuri.asp)
EDIT:
Here's a working js-fiddle.
var result = 'Firstname%20Lastname';
var result = decodeURI(result);
document.getElementById('demo').innerHTML = result;
http://jsfiddle/p82HN/
That data is URL-encoded, so use decodeURI
or decodeURIComponent
to decode it:
var result = decodeURI(input);
Looks like you need urldecode the data, check out decodeURIComponent()
本文标签: javascriptRemoving 20 on outputStack Overflow
版权声明:本文标题:javascript - Removing %20 on output - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://roclinux.cn/p/1744098506a2533345.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论