2012-10-05 18 views
0

我想在图像上启动一个函数。 我用JQueryThumbGallery与收藏,我想以检索图像ID图像上的Ajax函数

我的代码是

<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_horizontal_100percent_buttons.html

感谢 FC

回答

0

更改你的PHP代码来呈现这样的img标签标记(仅HTML!无功能迷上了)

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

现在使用一些unobutrusive 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>