最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Input box in jQuery UI Accordion Header - Stack Overflow

programmeradmin1浏览0评论

I have jQuery UI accordion with input box on header:

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

/

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. Is there any way to get rid from this behaviour, and use space and arrows, when typing there?

I have jQuery UI accordion with input box on header:

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

http://jsfiddle/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. Is there any way to get rid from this behaviour, and use space and arrows, when typing there?

Share Improve this question asked Sep 12, 2013 at 16:22 user1702401user1702401 1,6581 gold badge16 silver badges18 bronze badges 3
  • I don't understand your question. I'm able to enter input into the text field fine. – j08691 Commented Sep 12, 2013 at 16:24
  • Check this question and the answer stackoverflow./questions/5511785/… – Marko Commented Sep 12, 2013 at 16:24
  • Yes, I'm able to enter some text into the text box, but it's not possible to enter space; and to use arrow keys to navigate within text. Arun's answer solves this problem. – user1702401 Commented Sep 12, 2013 at 16:55
Add a ment  | 

3 Answers 3

Reset to default 6

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:

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

jsFiddle example

The below code worked well for me:

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

评论列表(0)

  1. 暂无评论