当用户在div中键入内容时,我想从另一个div下面滑下div。
这是HTML
<div id="search-container">
<input type="text" name="search-input" id="search-input" placeholder="🔎 type to search...">
</div>
div从search-container
下面滑下来
<div class="container" id="search-result-container" class="hidestuff" >
div qazxsw poi中的一些JS可能很有用
search-result-container
关于如何实现这一点的任何想法?非常感谢
<script>
$('#search-result-container').hide();
$('#search-input')
.on('keyup', function(e) {
var input = $(this).val();
input.length ?
$('#search-result-container').show() :
$('#search-result-container').hide();
})
</script>
方法在这里很有用
.slide<Down/Up>()
$('#search-input').on('input', function(e) {
var input = $.trim( this.value );
if ( input.length > 0 )
$('#search-result-container').stop().slideDown();
else
$('#search-result-container').stop().slideUp();
});
.hidestuff {
display: none;
background: #ddd;
padding: 20px;
}
专业提示:
<script src="//code.jquery.com/jquery-3.1.0.js"></script>
<div id="search-container">
<input type="text" name="search-input" id="search-input" placeholder="🔎 type to search...">
</div>
<div class="container hidestuff" id="search-result-container">
Some JS in the div search-result-container that might be usefull
</div>
事件注册任何类型的输入更改(如粘贴等)"input"
,因为只有第一个适用class="" class=""
删除包装空格