简体   繁体   English

jQuery UI对话和Textarea焦点问题

[英]jQuery UI Dialog and Textarea Focus Issue

I'm working on a modal comment system using jQuery and jQuery UI, but I'm having some issues with focus. 我正在使用jQuery和jQuery UI开发模态注释系统,但我有一些焦点问题。 I have a series of divs inside the modal to switch between Login and Add comment, as below: 我在模态中有一系列div来在Login和Add注释之间切换,如下所示:

<div id="modal" title="Loading">
 <div id="modalContent"></div>

 <div id="modalLogin">
  <div class="loginBox"></div>
  <div class="addCommentBox"></div>
  <div class="commentReview"></div>
 </div>
</div>

Inside of the addCommentBox div, I've got the comment code: 在addCommentBox div里面,我有评论代码:

 <form action="/comments/add" class="addCommentForm" name="addCommentForm" method="post">
  <textarea name="content" class="addCommentContent"></textarea>
  <button value="Add Comment" type="submit" class="commentPost"/>
  <button value="Clear Comment" type="submit" id="clearComment"/>
 </form>

The issue is that about half the time after opening the dialog the textarea inside the addCommentBox div doesn't react to keyboard inputs when selected. 问题是打开对话框后大约一半的时间, addCommentBox div中的textarea在选择时不会对键盘输入做出反应。 The mouse works correctly and will allow text to be selected, but keyboard control does nothing. 鼠标正常工作,将允许选择文本,但键盘控制不执行任何操作。

I have no event listeners on the textarea. 我在textarea上没有事件监听器。 I've got some on the buttons, but they are targeting only the buttons. 我在按钮上有一些,但它们只针对按钮。

The only thing that happens in the HTML seems to be the fact that every time I click on the modal, the z-index increases for the overall modal div. HTML中唯一发生的事情似乎是每次点击模态时,z-index会增加整个模态div。 I have set the addCommentBox div to have a z-index of 9999, greater than the z-index of the modal. 我已经将addCommentBox div设置为具有9999的z-index,大于模态的z-index。

Any suggestions or directions to research would be greatly appreciated. 任何建议或研究方向将不胜感激。 Thanks! 谢谢!

If it's happening "half the time" that's a hard one. 如果它发生在“一半的时间”,这是一个艰难的。 Test it on some other browsers to see if the same thing happens. 在其他一些浏览器上测试它,看看是否发生了同样的事情。

How are you hiding loginBox and commentReview? 你是如何隐藏loginBox和commentReview的? If you're using opacity it may be that something you can't see is sitting on top of the textarea. 如果你正在使用不透明度,那么你可能看不到的东西就是坐在textarea的顶部。

You won't see elements with opacity of 0, but they're still there in every other respect. 你不会看到不透明度为0的元素,但它们仍然存在于其他所有方面。 They will accept mouse events, stopping you from clicking on the textarea. 他们将接受鼠标事件,阻止您点击textarea。

If you can see the textarea, then it doesn't sound like a z-index issue to me. 如果你能看到textarea,那对我来说听起来不像是z-index问题。

When opening the dialog, try focusing the textbox during on the "open" function. 打开对话框时,尝试在“打开”功能期间将文本框聚焦。

$('#modal').dialog({
    open: function () {
        $('textarea[name=content]').focus();
    }
});

Sounds like the problem is with something else on the page. 听起来像问题在于页面上的其他内容。 Have you tested this by putting the above feature it's own page separate from all other functionality? 您是否通过将上述功能与其他所有功能分开来测试了这一点?

如果未设置,请尝试设置textarea的TABINDEX属性。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM