最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How can I escape backslash while adding html markup using Jquery appentTo function - Stack Overflow

programmeradmin23浏览0评论

On the click of a button I am dynamically adding the following Div to my web page.

The problem is the image source cannot be found due to the incorrect path caused by the backslash just before "\Content". The backslash is already reserved to escape quotes.

How can I workaround this.

$("<div class=\"input-append\"><label style=\"background-color:#e0ffff\">" + artistVal + "</label><img onclick=\"RemoveArtist()\" id=\"removeartist\" src=\"\Content\bootstrap\img\cross-button.png\" /></div>").appendTo(addDiv);

I am getting an error 400 pulling the image added to the div

Request URL:http://myhost:53159/Content%08ootstrapimgcross-button.png

On the click of a button I am dynamically adding the following Div to my web page.

The problem is the image source cannot be found due to the incorrect path caused by the backslash just before "\Content". The backslash is already reserved to escape quotes.

How can I workaround this.

$("<div class=\"input-append\"><label style=\"background-color:#e0ffff\">" + artistVal + "</label><img onclick=\"RemoveArtist()\" id=\"removeartist\" src=\"\Content\bootstrap\img\cross-button.png\" /></div>").appendTo(addDiv);

I am getting an error 400 pulling the image added to the div

Request URL:http://myhost:53159/Content%08ootstrapimgcross-button.png
Share Improve this question edited Nov 21, 2013 at 15:04 BenMorel 36.7k51 gold badges205 silver badges336 bronze badges asked Sep 1, 2013 at 21:12 MilligranMilligran 3,1719 gold badges46 silver badges57 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 3

You can either use double backslashes (\\) in file paths, or use forward slashes (/). Using a forward slash is more reliable, since backslashes don't work correctly on all web servers.

Use slash instead of backslash for your src element. This way you avoid the escaping problem inside URLs

发布评论

评论列表(0)

  1. 暂无评论