admin管理员组文章数量:1208155
I'm loading a bunch of files as background-image
using jQuery and I have this image that will simply not load. The browser does not throw any error.
I know the problem is that the file name contain parentheses ()
, but I've tried all sorts of things and nothing works. This is not a duplicate from this question as the solution there does not work.
This is the URL of the file
(1).jpg
I've tried different things in Javascript with no luck.
unescape(str);
encodeURI(str)
Even directly replacing the characters
str.replace("(", "%28");
str.replace(")", "%29");
Even by pure desperation
str.replace("(", "(");
str.replace(")", ")");
Help me StackOverflow, you are my only hope.
Please do not suggest to change the file name. I do not have access to that file.
I'm loading a bunch of files as background-image
using jQuery and I have this image that will simply not load. The browser does not throw any error.
I know the problem is that the file name contain parentheses ()
, but I've tried all sorts of things and nothing works. This is not a duplicate from this question as the solution there does not work.
This is the URL of the file
http://oceanhotelsimages.com/uploads/200x150_Privilege_Lounge_OBS_05_(1).jpg
I've tried different things in Javascript with no luck.
unescape(str);
encodeURI(str)
Even directly replacing the characters
str.replace("(", "%28");
str.replace(")", "%29");
Even by pure desperation
str.replace("(", "(");
str.replace(")", ")");
Help me StackOverflow, you are my only hope.
Please do not suggest to change the file name. I do not have access to that file.
Share Improve this question edited May 23, 2017 at 12:31 CommunityBot 11 silver badge asked Apr 10, 2015 at 2:26 PierPier 10.8k17 gold badges72 silver badges118 bronze badges 01 Answer
Reset to default 26The solution was easier than I thought. I was missing the quotes when declaring the url of the CSS property.
$(this).css({
"background-image": "url('" + someString + "')"
});
本文标签: javascriptUsing image URL with parentheses as background with jQueryStack Overflow
版权声明:本文标题:javascript - Using image URL with parentheses as background with jQuery - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1738732392a2109396.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论