dongyi1921
dongyi1921
2014-04-28 17:11

如何使用jquery更改动态内容的类名

  • php
  • html
  • javascript
  • jquery

In my php file I have this code section to get all jpg files form a folder and put them in to img tags.

if ($handle = opendir($dir)) {
    while (false !== ($file = readdir($handle))) {
       if ($file != "." && $file != ".." && strtolower(substr($file, strrpos($file, '.') + 1)) == 'jpg') {
           echo '<div class="image_slider"><img src ="' . $dir . $file . '"/></div>';
       }
    }
    closedir($handle);
}

and then I want to change displaying image by clicking on a links call previous and next.

To do so I'm using jQuery this way..

To show first image without clicking any thing

 $( ".image_slider img" ).first().addClass( "active" );

and then for the other images to load user must clik prvs or next links.

function next_img(){
        $( ".image_slider img" ).closest().next( "active" );
    }

but this function is not working. It doesn't change the class "active" from first one to second one.

I feel I'm missing something. but couldn't find it.

Thank you

  • 点赞
  • 回答
  • 收藏
  • 复制链接分享

4条回答

为你推荐

换一换