javascript - jQuery prevent default functionality in dropdown menu - Stack Overflow

I have created a smart search ponent inside a dropdown menu. User should be allowed to search within th

I have created a smart search ponent inside a dropdown menu. User should be allowed to search within the dropdown depending upon the value entered in the input=text provided in menu.

But when i am clicking on the input the menu gets closed. I tried using preventDefault as well but still it is not working.

HTML:

<input type="text" readonly="readonly" value="">
<button class="btn i dropdown-toggle" data-toggle="dropdown"> <i class="caret-down"></i>
</button>
<div class="dropdown-menu smart">
    <input type="text" placeholder="Search">
    <ul class="search-options">
        <li><a href="#">Something</span></a>
        </li>
    </ul>
</div>

JS:

// jQuery to prevent default close 
$('body').on('click', '.dropdown-menu.smart input', function (event) {
    event.preventDefault();
});

I have created a smart search ponent inside a dropdown menu. User should be allowed to search within the dropdown depending upon the value entered in the input=text provided in menu.

But when i am clicking on the input the menu gets closed. I tried using preventDefault as well but still it is not working.

HTML:

<input type="text" readonly="readonly" value="">
<button class="btn i dropdown-toggle" data-toggle="dropdown"> <i class="caret-down"></i>
</button>
<div class="dropdown-menu smart">
    <input type="text" placeholder="Search">
    <ul class="search-options">
        <li><a href="#">Something</span></a>
        </li>
    </ul>
</div>

JS:

// jQuery to prevent default close 
$('body').on('click', '.dropdown-menu.smart input', function (event) {
    event.preventDefault();
});
Share Improve this question edited Nov 22, 2013 at 12:15 palaѕн 74k17 gold badges122 silver badges139 bronze badges asked Nov 22, 2013 at 12:13 well_alrightwell_alright 1131 gold badge2 silver badges5 bronze badges 1
  • Your code seems to be correct and should be working. But this is inplete - plz. provide also css and dropdown code so I'll be able to check this out. Jsfiddle would be most apreciated. – Hexodus Commented Nov 22, 2013 at 12:20
Add a ment  | 

1 Answer 1

Reset to default 5

Write the following code and it should keep the dropdown open

$('.dropdown-menu').click(function(e) {
        e.stopPropagation();
});

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745630671a4637089.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信