简体   繁体   English

jQuery UI Accordion Header中的输入框

[英]Input box in jQuery UI Accordion Header

I have jQuery UI accordion with input box on header: 我在标题上有输入框的jQuery UI手风琴:

<h3><input type="text" /></h3>

http://jsfiddle.net/7VN8h/ http://jsfiddle.net/7VN8h/

As expected, Accordion catches all space and arrow keypresses, that take place within header - so it's not possible to write into input box correctly. 正如预期的那样,Accordion会捕获所有在标题内发生的空格和箭头按键 - 因此无法正确写入输入框。 Is there any way to get rid from this behaviour, and use space and arrows, when typing there? 有没有办法摆脱这种行为,并在键入时使用空格和箭头?

You can stop the propagation of key events from the input control 您可以停止从输入控件传播关键事件

$(function () {
    $("#accordion").accordion();

    $("#accordion h3 input").on('keydown', function (e) {
        e.stopPropagation();
    })
});

Demo: Fiddle 演示: 小提琴

If you're looking to be able to enter input into the text field without triggering the accordion element, add this: 如果您希望能够在不触发accordion元素的情况下在文本字段中输入输入,请添加以下内容:

$('input').click(function (e) {
    e.stopPropagation();
});

jsFiddle example jsFiddle例子

The below code worked well for me: 以下代码对我有用:

$('#TSResultContent input[type="textbox"]').keydown(function (e)  {
    e.stopPropagation();
});

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

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