为什么我的 jQuery UI 对话框完成打开效果后会失去焦点?

发布于 2024-09-16 10:23:59 字数 780 浏览 2 评论 0原文

我正在使用 jQuery UI 对话框向我的网站添加一些新闻。每次我单击添加新闻按钮时,都会打开带有文本区域的对话框。实际上,我正在使用 ckeditor 替换 textarea ,但碰巧我不能由于 focus 问题,在文本编辑器中键入(至少我认为这是问题所在)。

一探究竟。正如我单击添加新闻按钮一样,对话框开始打开并显示其效果。请注意黄色边框的 textarea 意味着它在显示时处于焦点状态(使用 Chrome)。 替代文字 单击缩放

请注意,当对话框完成显示时,它不再聚焦,我 遇到了麻烦

因为这个alt text 点击缩放

另外,检查我的代码http://jsfiddle.net/pzHr2/

I'm using jQuery UI Dialog for adding some news to my site. Every time I click add news button, the dialog should open with the text area. Actually, I'm using ckeditor replacing the textarea and it happens that I can't type inside the text editor due to focus issue (at least I think this is the problem).

Check it out. As just as I click add news button the dialog start to open with its effect. Notice the yellow bordered textarea meaning that it's focused (using Chrome) while it's appearing.
alt text
Click to zoom

Notice then that when the dialog finishes appearing, it isn't focused anymore and I'm having trouble because of this

alt text
Click to zoom

Also, check my code http://jsfiddle.net/pzHr2/

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

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

发布评论

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

评论(1

黯淡〆 2024-09-23 10:23:59

这不是一个有据可查的(非常轻描淡写)功能,您可以像传递对象一样传递对象 .show() UI 方法 在您的选项中如下所示:

show:{ effect: 'slide', complete: function() { $("textarea").first().focus(); }},

这将运行 .focus() 当动画完成时,您可以在这里尝试一下。如果您好奇为什么会这样,你可以在这里看看

注意:这个答案适用于jQuery UI 1.8.4+(因为您使用的是.button()),它不会工作对于 1.7.x 用户。

It's not a very well documented (tremendous understatement) feature that you can pass an object just as you can to the .show() UI method like this in your options:

show:{ effect: 'slide', complete: function() { $("textarea").first().focus(); }},

This runs the .focus() when the animation completes, you can give it a try here. If you're curious as to why this works, you can take a look here.

Note: this answer is for jQuery UI 1.8.4+ (since you're using .button()), it won't work for 1.7.x users.

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