jquery的lazyloading源码疑惑

lazyload的源码里有一段是说当图片没有设置src属性的时候就添加默认的placeholder图片~但是为什么if判断里还要加$self.attr("src") === false呢~直接undefined就可以了吧~

if ($self.attr("src") === undefined || $self.attr("src") === false) {
  if ($self.is("img")) {
                    $self.attr("src", settings.placeholder);
                }
            }
阅读 2k
1 个回答

As of jQuery 1.6, the .attr() method returns undefined for attributes that have not been set. To retrieve and change DOM properties such as the checked, selected, or disabled state of form elements, use the .prop() method.

jQuery 1.6之后(包含1.6)确实只需要处理undefined就行了,如果要兼容旧版本,就得像作者一样。

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题