jQuery UI modal dialog captures all keypress so I can't input text inside it

冷暖自知 提交于 2019-12-09 07:53:33

问题


I create modal dialog with form inside it (with some text input). And I just can't enter the text inside the textbox. Dialog blocks keyboard input.

Here is my simplified example:

<div id="modal-dialog">
    <label for="my-text">TRY to input text...</label>
    <textarea id="my-text" style="position:relative; z-index:1"></textarea>
</div>
<script type="text/javascript">
    var dialog = $('#modal-dialog').dialog({ modal: true });
</script>

Note: You may ask - why did I mentioned about "position:relative; z-index:1"? Because it works fine without it. But I can't remove it because of design.

Note: not modal dialog works fine too.

I'm using jQuery 1.6.2 + jQuery UI 1.8.14


回答1:


The z-index is the problem. Here is an exemple ( http://jsfiddle.net/c3BPP/ ) of your code with a bigger z-index and it works.




回答2:


You can also lower the z-index of the JQuery dialog:

var dialog = $('#modal-dialog').dialog({ 
    modal: true,
    zIndex: 500
});

By default, it is 1000. Of course your relative or absolute positioned elements needing text input need to be greater than the z-index of the dialog still.




回答3:


I found that the <form> tag in my dialog was getting a z-index of 1, preventing any of the controls from working. Instead of changing the z-index for each control, simply changing the z-index of the <form> tag to 1010 (a value higher than the default of the dialog) worked for me.




回答4:


Adding tabindex="-1" helped me resolve this problem.

Here's an example:

 <div class="modal fade" tabindex="-1" id="error" role="dialog">


来源:https://stackoverflow.com/questions/6949059/jquery-ui-modal-dialog-captures-all-keypress-so-i-cant-input-text-inside-it

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!