0

我想在图像上启动一个功能。我将 JQueryThumbGallery 与灯箱一起使用,我想检索图像 ID

我的代码是

<div class='thumbHolder' **data-id="MY-ID"** data-title="<?php echo '<span class=\'io_home\'>'.$row['io'].'</span><br /> '.$row['first_name'].' '.$row['last_name'].'<br/><span class=\'voti_home\'>'.$row['tot_voti'].' VOTI</span>'; ?>">
  <a rel="prettyPhoto[ajax]" href="index.php/image/view_image?ajax=true&width=700px&height=450px&id=<?php echo $row['id']; ?>" >
  <img class="thumb_hidden" src="<?php echo base_url().'upload/concorso1/thumb/'.$row['url']; ?>" width="151" height="120" alt="<?php echo $row['first_name'].' '.$row['last_name']; ?>" />
                                </a>

                            </div>

jquery函数是

        function overThumb(i,j){

        //function called when mouse over thumb holder (plus returned item number: i = first level, j = second level)
        console.log('overThumb: ', i,' , ', j);
    }

我需要从我打开的图像中检索 ID(overThumb 功能)。我曾尝试设置 data-id-i 和 data-id-j 但我还没有了解应该如何使用它们。你能帮助我吗?

链接到脚本

http://www.interactivepixel.net/ccThumbGallery/index_grid_horizo​​ntal_100percent_buttons.html

谢谢 fc

4

1 回答 1

0

更改您的 PHP 代码以呈现这样的 img 标签标记(仅 HTML !没有连接函数)

<img class="thumb_hidden" src="Somepath/someimage.jpg" 
               data-myAttr="my custom val" id="someUniqueID" alt="some text" />

现在使用一些普通的javascript

<script type="text/javascript">
 $(function(){
   $("img.thumb_hidden").mouseover(function() {
       var ourImg=$(this);
       var urlOfImage=ourImg.attr("href");
       var idOfImage=ourImg.attr("id");
       //let's get the HTML5 data attribute as well
       var myCustomVal=ourImg.data("myAttr");
       //Now use these to make ajax call as necessary
   });    
 });
</script>
于 2012-10-05T21:55:30.440 回答