onBlur Javascript 事件,检查元素是否具有焦点

发布于 2024-09-15 08:11:52 字数 429 浏览 1 评论 0原文

我试图找到一个看似复杂的简单问题的解决方案!

我有一个文本区域,用户可以在其中更新他们的状态。 在它下面有一个复选框(例如:用户可以选择是否发布推文状态)。

我尝试做的是: 1/ 当文本获得焦点时,文本区域会扩展,这样就可以了。

2/当文本区域失去焦点时,当用户单击它时,它会崩溃。这也很好......

唯一的问题是,如果用户单击复选框,文本区域也会折叠,但我想阻止它。

它应该折叠并在模糊时执行该函数,但如果用户尝试与复选框交互则不会。

我在此页面上设置了一个示例: http://favosaurus.com/dev/onblur.php

感谢您的建议。

I am trying to find a solution to a simple thing, that looks complex!

I have a textarea where users can update their status.
Underneath it I have a checkbox (ex: for the user to choose to tweet the status or no).

What I try to do is this:
1/ When the textera get the focus, the textarea expands, for that it's fine.

2/ When the textarea loose focus, so when the user clicks out of it, it collapse. That's fine too...

The only problem is that if the user click on the checkbox, the textarea collapse too but I want to prevent it.

It should collapse and execute the function on blur, but not if the user try to interact with the checkbox.

I set up an example on this page: http://favosaurus.com/dev/onblur.php

thanks for your suggestions.

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

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

发布评论

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

评论(1

毁梦 2024-09-22 08:11:52

您将需要使用 Javascript。

伪代码:

if input blur,  and checkbox not clicked:

     do normal blur action.

else:

     process checkbox click
     focus input again

You're going to need to use Javascript.

Pseudocode:

if input blur,  and checkbox not clicked:

     do normal blur action.

else:

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