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
1 Answer
Reset to default 5Write 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条)