[英]jQuery Load not parsing HTML Variable
I would like to build a list of articles with a different thumbnail for each one, and this thumbnail should be loaded using jquery.load, but I have one problem: 我想为每个文章构建一个带有不同缩略图的文章列表,并且应该使用jquery.load加载此缩略图,但是我有一个问题:
The class of each article's thumbnail in html is as follows: html中每篇文章的缩略图的类如下:
thumb{ARTICLE_ID}
Now, given this basic example: 现在,给出以下基本示例:
<i class="thumb{ARTICLE_ID}"></i>
<script>$('thumb{ARTICLE_ID}').load("https://somewebsites.com .itemimg");</script>
How can I Make jQuery parse "{ARTICLE_ID}" variable? 如何使jQuery解析“ {ARTICLE_ID}”变量?
Thank you. 谢谢。
You can achieve it this way, for example: 您可以通过这种方式实现,例如:
<i class="thumbnail" data-article-id="{ARTICLE_ID}"></i>
<script>
$('.thumbnail').each(function () {
$(this).load("https://somewebsites.com/" + $(this).data('article-id'))
})
</script>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.