【问题标题】:How to retrieve the selected image ID如何检索选定的图像 ID
【发布时间】:2012-08-10 02:33:52
【问题描述】:

我在我的 rails 3 应用程序中使用了 Galleria 插件。我需要从所选图像中检索 img ID 以更新我的数据库。 我尝试使用方法.getActiveImage,但我真的不知道如何实现它。

如果您对如何使此代码正常工作有任何想法,或者您有其他解决方案可以推荐,请告诉我。

谢谢。

【问题讨论】:

    标签: jquery ruby-on-rails ruby-on-rails-3 galleria


    【解决方案1】:

    您可以监听image 事件并从事件对象中获取galleriaData 属性中的原始IMG 元素:

    Galleria.on('image', function(e) {
        alert( e.galleriaData.original.id );
    });
    

    http://galleria.io/docs/api/events/#image

    【讨论】:

    • 非常感谢。你拯救了我的一天。
    【解决方案2】:

    简单

    $(function() {  // <-- on dom ready
        $('img').click(function() {  // <-- bind click event to all images
            alert(this.id); // <-- alert current clicked image id
            // or this $(this).prop('id');  this using jquery object
        });
    });​
    

    【讨论】:

      【解决方案3】:

      我建议为您插件的所有图像提供相同的类名,因此当您选择插件中的图像时,这将为您提供来自插件的图像 id。

      <img class="agree" id="imageid" src="http://i158.photobucket.com/albums/t116/kaloesche68/Olympics.jpg" width="256" height="256"/>​
      
      $(document).ready(function() {
        $("img.agree").click(function(){
             alert($(this).attr("id"));
             return false;
          });
      
      });
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2017-01-27
        • 1970-01-01
        • 1970-01-01
        • 2020-01-29
        • 1970-01-01
        • 1970-01-01
        • 2019-11-24
        • 1970-01-01
        相关资源
        最近更新 更多