TypeError:$(...).parents(...).size不是函数 [英] TypeError: $(...).parents(...).size is not a function

查看:74
本文介绍了TypeError:$(...).parents(...).size不是函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个基本脚本,可让我单击网站的背景,但不包括#content.

I have a basic script which allows me to click on the website's background, excluding #content.

将jQuery升级到3.1.0版本后,出现此错误: TypeError: $(...).parents(...).size is not a function.

After upgrading jQuery to 3.1.0 version, I get this error: TypeError: $(...).parents(...).size is not a function.

<script type="text/javascript">
  $(function() {
    $("#background").click(function(e) {
      if (e.target.id == "wrapper" || $(e.target).parents("#wrapper").size()) 
      {
        // do nothing
      } 
      else
      {
        window.open('http://example.com');
      }
    });
  })
</script>`

我不知道如何解决它. jQuery已正确加载.请帮忙.

I don't know how to fix it. jQuery is loaded properly. Please help.

推荐答案

size()于几年前已被弃用,并在版本3中被删除...改用length

size() was deprecated years ago and removed in version 3 ... use length instead

if (e.target.id == "wrapper" || $(e.target).parents("#wrapper").length)

您要做的就是在 size() docs 中查找此内容

All you had to do was look this up in the size() docs to find this out

这篇关于TypeError:$(...).parents(...).size不是函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆