开发者

javascript split and url encoding

开发者 https://www.devze.com 2023-03-20 17:19 出处:网络
I have a string of a url: var url = \"/_imgs/media/image/Picture%201.png\" When I try to split it lke: var 开发者_StackOverflowpath = url.split(\'image/\');

I have a string of a url:

var url = "/_imgs/media/image/Picture%201.png"

When I try to split it lke:

var 开发者_StackOverflowpath = url.split('image/');
console.log(path);

gives:

["/_imgs/media/", "Picture%201.png"]

ok fine, but when I do

console.log(path[1]);

I get:

/Picture%png

What is happening here?


It looks like a problem with firebug rather than the javascript. Chrome displays the second console log fine, but firebug misses out the %20 (url encoded space).

Interestingly, if you try:

console.log(path[1].indexOf('2'));

You get 8, which is the correct position. So the variable contains the right data, it's just the console showing it wrong.

0

精彩评论

暂无评论...
验证码 换一张
取 消