gpt4 book ai didi

javascript - 在 collapsible-set 中打开了哪个动态添加的 collapsible?移动版

转载 作者:行者123 更新时间:2023-11-30 05:39:05 26 4
gpt4 key购买 nike

我有一个 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");

最佳答案

您应该将 collapsibleexpand 绑定(bind)到 collapsible 而不是 collapsibleset。当您在 collapsibleset 中有 _collapisbleset_s 时,将事件绑定(bind)到 collapsibleset。此外,在动态注入(inject)事件时将事件委托(delegate)给 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

关于javascript - 在 collapsible-set 中打开了哪个动态添加的 collapsible?移动版,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21832950/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com