【问题标题】:Which dynamicly added collapsible is opened inside collapsible-set? jQuery mobile哪个动态添加的可折叠在可折叠集中打开? jQuery手机
【发布时间】:2023-03-12 19:21:01
【问题描述】:

我有一个 Collapsible-set(可折叠 5-10 个)并使用此代码查找已打开:

$("#mySet").on("collapsibleexpand", function (e) 
{
    var selected = $(".ui-icon-minus").parent().parent().attr("my-data");

// more code...

当在可折叠集内打开可折叠时,此方法有效。或者在打开新的可折叠之前关闭当前打开的。但是,如果可折叠物已打开并单击我的可折叠集内的新可折叠物,则会失败,并且我会从之前打开的值中获取值。

有更好的方法吗? 使用 jQuery 移动版 1.4.0

我也试过这个,但我只能在我的可折叠集内获得第一个可折叠

var foo = $("[data-role=collapsible]").attr("my-data");

【问题讨论】:

  • 您想在什么时候查看打开了哪个折叠项?关闭另一个?
  • 每次打开折叠式。如果我的可折叠套装有 10 个可折叠的,我想知道打开了哪个
  • 你需要将collapsibleexpand绑定到collapsible而不是collapsiblesetjsfiddle.net/Palestinian/A5vFz
  • @Omar 我将我的可折叠动态添加到我的可折叠集合中。会试试你的小提琴!
  • @Omar 我的活动工作,我只需要获取可折叠的文本。试过你的小提琴,但没有动态工作......

标签: javascript jquery jquery-mobile


【解决方案1】:

您应该将collapsibleexpand 绑定到collapsible 而不是collapsibleset。当 collapsibleset 中有 _collapisbleset_s' 时,将事件绑定到 collapsibleset。此外,在动态注入事件时,将事件委托给data-role="collapsible".ui-collapsible

另一个注意事项,data-role="collapsible-set" 在 jQM 1.4 中已弃用,并将在 1.5 中删除,请改用 data-role="collapsibleset"(只需删除 连字符)。

$(document).on("collapsibleexpand","[data-role=collapsible]", function () {
    $(this).doSomething();
});

Demo

【讨论】:

  • 添加数据角色解决了! $("#mySet").on("collapsibleexpand", "[data-role=collapsible]", function (e) ... //
猜你喜欢
  • 1970-01-01
  • 2022-01-11
  • 2012-01-14
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多