检测细节元素的打开或关闭 [英] Detecting the opening or closing of a details element

查看:111
本文介绍了检测细节元素的打开或关闭的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何检测在Java中打开或关闭详细信息元素的时间?除了将侦听器附加到click函数并检查open属性是否已设置之外。

How can I detect when a details element is opened or closed in Javascript? Other than attaching a listener to the click function and checking if the open attribute is set or not.

推荐答案

由于此问题仍被否决,因此我无法删除它,因为它是公认的答案,我将有关最新解决方案,请参阅@Daniel Herr的帖子。

Since this is continuing to be voted down, and I can't remove it since it's the accepted answer, I'll refer to @Daniel Herr's post as a more up-to-date solution.

旧答案:

<details id="element">
   <p>Details</p>
</details>

<script>
   var isOpen = ($("#element").attr("open") == "open");

   alert ("Open = " + isOpen);
</script>

这篇关于检测细节元素的打开或关闭的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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