2012-10-05 23 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>