【问题标题】:accessing attr attribute from image array using jquery使用 jquery 从图像数组访问 attr 属性
【发布时间】:2012-03-22 07:26:51
【问题描述】:
 <script type="text/javascript" >
            $(document).ready($(function () {
                var images = $("img.landscape");
                for (var i = 0; i < images.length; i++) {
                    if (images[i].attr("src") == "") {
                        images.hide();
                    }
                }
            }));
        </script>

这是我的 jquery 函数。我正在使用转发器从数据库中渲染图片和文本。有些图像将是空洞的思想,需要使它们不可见。 images[i].attr("src") 这段代码似乎不起作用,因为它不会访问 attr 方法。我是 jquery 的新手,如果能提供任何帮助,我将不胜感激。谢谢

【问题讨论】:

    标签: jquery


    【解决方案1】:

    检查空源后,您需要隐藏单个图像。

    替换:

    images.hide();
    

    与:

    images[i].hide();
    

    【讨论】:

      【解决方案2】:
      $(document).ready($(function () {
        $("img.landscape").each(function(){
          if($(this).attr('src') == ''){
            $(this).hide();
           }
          });
      });
      

      【讨论】:

      • 感谢您的解决方案在我在最后一组右括号中添加了一个额外的括号后的帮助。非常感谢,非常感谢
      猜你喜欢
      • 2011-08-14
      • 1970-01-01
      • 2013-09-17
      • 2021-03-26
      • 2012-08-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-10-09
      相关资源
      最近更新 更多