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

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

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

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1742416134a4439782.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信