douping3427 2013-12-17 22:03
浏览 12
已采纳

选择具有特定值的html数据属性[关闭]

The html code

<div id="slider">
    <?php
    while($gal = mysql_fetch_assoc($gallerydb))
        {?>
        <img data-store="<? echo $gal["ImageID"] ?>" src="SiteAdministration/ControlCenter/Gal/<? echo $gal["ImgPfad"] ?>"><?
        }?>
</div>

The jQuery code

$(document).ready(function() {

      $('#slider img[data-store='" + 2 + "']').fadeIn(300);

});

The html code shows a div with a while construct, that gets all images from a specific folder and adds an ID out of a database(numbers).

The jQuery code shows my attempt to select a img with a specific data-attribute value.

The problem is, that the img won't fade in, I suggest I messed up the selector.

Another question would be, how can I make it work, so that the selector starts with the lowest ID numer and ends with the highest, because the ID's can change.

Thanks in advance.

EDIT:

To solve my changing ID problem I just created another variable which increases automatically. If someone wants to know a solution.

<div id="slider">
    <?php
    $id = 1;
    while($gal = mysql_fetch_assoc($gallerydb))
        {?>
        <img data-store="<? echo $id++ ?>" src="SiteAdministration/ControlCenter/Gal/<? echo $gal["ImgPfad"] ?>"><?
        }?>
</div>

sliderStart = 1;
sliderNext = 2;

$(document).ready(function() {

$('#slider img[data-store="' + 1 + '"]').fadeIn(300);
startSlider();

});

function startSlider(){

count = $('#slider img').size();

loop = setInterval(function(){

    if(sliderNext > count) {        
        sliderNext = 1;
        sliderStart = 1;        
    }

    $('#slider img').fadeOut(300);
    $('#slider img[data-store="' + sliderNext + '"]').fadeIn(300);

    sliderStart = sliderNext;
    sliderNext = sliderNext + 1;

}, 3000)

}
  • 写回答

1条回答 默认 最新

  • douji6199 2013-12-17 22:08
    关注

    What PSL said, your doubles and singles are the wrong way around.

    Also, I would not use hyphens in your custom html attributes.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 wegame打不开英雄联盟
  • ¥15 公司的电脑,win10系统自带远程协助,访问家里个人电脑,提示出现内部错误,各种常规的设置都已经尝试,感觉公司对此功能进行了限制(我们是集团公司)
  • ¥15 救!ENVI5.6深度学习初始化模型报错怎么办?
  • ¥30 eclipse开启服务后,网页无法打开
  • ¥30 雷达辐射源信号参考模型
  • ¥15 html+css+js如何实现这样子的效果?
  • ¥15 STM32单片机自主设计
  • ¥15 如何在node.js中或者java中给wav格式的音频编码成sil格式呢
  • ¥15 不小心不正规的开发公司导致不给我们y码,
  • ¥15 我的代码无法在vc++中运行呀,错误很多