JQuery 获取所有;来自 的标签并在
  • 中显示它们

发布于 2024-10-03 17:00:15 字数 859 浏览 0 评论 0原文

这是我的 html(即时通讯使用 Galleria Image Gallery - 基于 JQuery)

<div id="galleria">
            <img alt="Productname 1" src="bens_img/1.jpg">
            <img alt="Productname 2" src="bens_img/2.jpg">
            <img alt="Productname 3" src="bens_img/3.jpg">
            <img alt="Guess what?" src="bens_img/4.jpg">
        </div>

伪代码

Get string from <alt> from <img>
Create a new <li> and paste the <alt> string from <img> in it

这应该使用所有(即:四个)img alt 字符串来完成。它应该看起来像这样:

<ul class="textformat">
<li>Productname 1</li>
<li>Productname 2</li>
<li>Productname 3</li>
<li>Guess what?</li>
</ul> <!-- yeah this was all done by java-script -->

This is my html (im using Galleria Image Gallery - JQuery Based)

<div id="galleria">
            <img alt="Productname 1" src="bens_img/1.jpg">
            <img alt="Productname 2" src="bens_img/2.jpg">
            <img alt="Productname 3" src="bens_img/3.jpg">
            <img alt="Guess what?" src="bens_img/4.jpg">
        </div>

Pseudo Code

Get string from <alt> from <img>
Create a new <li> and paste the <alt> string from <img> in it

This should be done with all (ie: four) img alt strings. It should look like this:

<ul class="textformat">
<li>Productname 1</li>
<li>Productname 2</li>
<li>Productname 3</li>
<li>Guess what?</li>
</ul> <!-- yeah this was all done by java-script -->

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

痴骨ら 2024-10-10 17:00:15

就像这样:

$("#galleria > img").each(function(i, ele) {
  $(".textformat").append("<li>"+$(ele).attr("alt")+"</li>");
});

Like so:

$("#galleria > img").each(function(i, ele) {
  $(".textformat").append("<li>"+$(ele).attr("alt")+"</li>");
});
沐歌 2024-10-10 17:00:15
$("img[alt]")

对于标记每个具有“alt”的图像

$("img[alt]")

for tag every image that has 'alt'

梦情居士 2024-10-10 17:00:15

您需要 .attr jQuery 选择器:

$('#galleria > img').each(function(){
  $('.textformat').append('<li>'+ $(this).attr('alt') +'</li>');
});

或者您可以使用 $('#galleria').find('img')$('#galleria' ).children('img')

You need the .attr jQuery selector:

$('#galleria > img').each(function(){
  $('.textformat').append('<li>'+ $(this).attr('alt') +'</li>');
});

Or you can use $('#galleria').find('img') or $('#galleria').children('img')

慈悲佛祖 2024-10-10 17:00:15

尝试使用 jQuery 的 map() 函数:

$('#galleria img').map(function() {
  return '<li>' + this.alt + '</li>';
}).appendTo('ul.textformat');

Try using jQuery's map() function:

$('#galleria img').map(function() {
  return '<li>' + this.alt + '</li>';
}).appendTo('ul.textformat');
二智少女猫性小仙女 2024-10-10 17:00:15

您可以扩展 Galleria 以将 alt 标签或描述放在另一个 div 中,不知道如何将其放入 li 中,我猜是一些 jQuery
<代码>
扩展:函数(){
this.bind(Galleria.IMAGE, 函数(e) {
$('.caption').html(this.$('信息描述').html());
})
}

You can extend galleria to put the alt tags or descriptions in another div, not sure how to put it into an li, some jQuery i guess

extend: function() {
this.bind(Galleria.IMAGE, function(e) {
$('.caption').html(this.$('info-description').html());
})
}

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文