jQuery 数据应该是可链接的吗?

发布于 2024-08-30 03:56:57 字数 374 浏览 2 评论 0原文

我正在尝试将多个 jQuery 数据条目添加到单个元素。

我怀疑以下内容会起作用

jQuery('td.person#a'+personId).data('email',thisPerson.email).data('phone',thisPerson.phone);

但是,当我这样做时,除了错误之外什么也没有得到。

jQuery('td.person#a'+personId).data('email',thisPerson.email);
jQuery('td.person#a'+personId).data('phone',thisPerson.phone);

是否有另一种方法可以在一个元素上获取多个数据条目?希望被束缚?

I'm trying to add multiple jQuery data entries to a single element.

I suspected that the following would work

jQuery('td.person#a'+personId).data('email',thisPerson.email).data('phone',thisPerson.phone);

However, I am getting nothing but errors when I do this.

jQuery('td.person#a'+personId).data('email',thisPerson.email);
jQuery('td.person#a'+personId).data('phone',thisPerson.phone);

is there another way to get more than one data entry on an element? Hopefully chained?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

┼── 2024-09-06 03:56:57

您可以将对象传递到 .data() 中,如下所示(已损坏所以为了防止水平滚动)

jQuery('td.person#a'+personId)
      .data({email:thisPerson.email, phone:thisPerson.phone});

要回答你的问题,是的它应该是可链接的,如果你发布你遇到的错误,这将有助于了解它为什么不起作用。

You can pass an object into .data(), like this (broken so to prevent horizontal scroll)

jQuery('td.person#a'+personId)
      .data({email:thisPerson.email, phone:thisPerson.phone});

To answer your question though, yes it should be chainable, if you post what errors you were getting that would help see why it isn't working.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文