jquery 捕获 onToggle

发布于 2024-09-12 09:23:43 字数 317 浏览 2 评论 0原文

我有一组 DIV,并在每个 DIV 中渲染 CheckBoxList。 DIV 的数量和 CheckBoxList 的数量是动态的。每个 div 都有一个与之关联的按钮,可以切换该特定 DIV 的可见性。

每次用户单击复选框时,我都需要在一个标签中显示该复选框的文本。我认为我应该在 DIV 的切换事件上附加一个事件,以便当 div 变得可见时,我可以在该 div 内的复选框的单击事件上绑定一个函数,该函数将显示单击的复选框的文本。

我正在努力寻找一种方法来捕捉 div 变得可见或不可见的情况。我如何知道在给定时间正在显示哪个 div?

还有其他方法可以做到这一点吗?

I have set of DIVs and i render CheckBoxList in each of them. Number of DIVs and number of CheckBoxLists are dynamic. Each div has a button associated with it which will toggle the visibility of that particular DIV.

Every time user clicks on a checkbox, i need to display the text of that checkbox in one label. I am thinking that i shud attach an event on the DIV's toggle event so that when the div becomes visible, i can bind a function on the click event of checkboxes inside that div which will display the text of clicked checkbox.

I am struggling to find a way to capture when the div becomes visible or invisible. How do i know which div is being displayed at a given time?

Is there any other way to do this?

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

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

发布评论

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

评论(2

假情假意假温柔 2024-09-19 09:23:43

如果您想在任何情况下将事件处理程序/操作绑定到它们:

$("div#theContainerId").find(":visible").each(function(/*Do Something*/));

如果您想在toggle()期间绑定一些其他操作(隐藏/显示除外),请执行以下操作:

$(".toggleTarget").toggle(function(){$(this).hide(); /* add more actions here */}, function(){$(this).show(); /* add more actions here */});

If you want to bind event handler / actions to them at any instance:

$("div#theContainerId").find(":visible").each(function(/*Do Something*/));

If you want to bind some other action (other than hide/show) during the toggle(), do this:

$(".toggleTarget").toggle(function(){$(this).hide(); /* add more actions here */}, function(){$(this).show(); /* add more actions here */});
皇甫轩 2024-09-19 09:23:43

您可以在启动时或每隔一段时间检查 div 是否可见。

这个选择器会告诉你

之后,您需要跟踪谁隐藏了它并让它调用一个函数,我认为

@bauer的链接可以工作,但可能会很昂贵。

如果这不是您想要的,请扩展您的问题。

You can check to see whether a div is visible or not on startup or at intervals.

this selector will tell you that.

after that you need to keep track of who is hiding it and have it call a function i think

@bauer's link would work i think but would possibly be expensive.

if this is not what you want then please expand your question.

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