简体   繁体   English

使用jQuery将html添加到div

[英]add html to div with jQuery

I am trying to add some additional html to a div with id slideshow using jQuery. 我正在尝试使用jQuery向id幻灯片添加一些额外的html到div。 My code: 我的代码:

$("#slideshow").append("<a id="prev" title="Previous Slide">Previous Slide</a><a id="next" title="Next Slide">Next Slide</a>");

This isn't working, can anyone tell me what I am doing wrong? 这不起作用,谁能告诉我我做错了什么?

You're mixing quotes. 你在混合报价。

Your string goes from the first " to the second " , meaning that the string only contains "<a id=" . 你的字符串从第一个"到第二个" ,这意味着字符串只包含"<a id=" The string is followed by the identifier prev , then another string, creating a syntax error. 该字符串后跟标识符prev ,然后是另一个字符串,从而产生语法错误。

Change the outer quotes around the string to ' , like this: 将字符串周围的外部引号更改为' ,如下所示:

'<a id="prev" title="Previous Slide">Previous Slide</a><a id="next" title="Next Slide">Next Slide</a>'

你没有逃脱你的报价最好的解决方法是将附加单引号

$("#slideshow").append('<a id="prev" title="Previous Slide">Previous Slide</a><a id="next" title="Next Slide">Next Slide</a>');

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM