jquery搜索框和按钮
jquery search box and button
我有一个按钮和文本框,当你将鼠标悬停在按钮上时,搜索框将使用这段JavaScript/jquery出现:
$('#search-button').hover(function () {
$('#search-text').show();
}, function () {
$('#search-text').hide();
});
但是,一旦您将鼠标悬停在按钮上,它将显示文本框,但是一旦您尝试将鼠标悬停在文本框上,它就会消失。有没有办法让文本框在将鼠标悬停在页面上时也保留在页面上。
这是描述问题的小提琴
你不需要
Jquery。Css样式将为您做到这一点!
通过将内容包装在元素中,您可以在包装器中显示/隐藏任何(/all)元素。我在下面做了一个基本的演示:
请注意,.search
类上的填充/背景仅用于演示,可以编辑/删除并仍保留其功能。
button {
display: none;
}
.search:hover button {
display: inline-block;
}
.search {
background: gray;
display: inline-block;
padding: 10px;
}
<div class="search">
<input type="text" placeholder="type here" />
<button>SEARCH</button>
</div>
但是,如果你被迫使用Javascript/jquery,那么我不会在这里复制它,而是参考chipChocolate.py的答案。
一个针对您问题的 JavaScript 解决方案。检查这个jsfiddle链接:
http://jsfiddle.net/ea45h80n/
$('.search').hover(function() {
$('#search-text').show();
}, function() {
$('#search-text').hide();
});
$('#search-text').hide();
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="search">
<button>SEARCH</button>
<input type="text" placeholder="type here" id='search-text' />
</div>
将hover
事件附加到#search-button
并#search-text
。
$('#search-text').hide();
$('#search-button, #search-text').hover(function() {
$('#search-text').show();
}, function() {
$('#search-text').hide();
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<input id="search-text" type="text" /
><input id="search-button" type="button" value="Search" />
删除第二个函数。 这是悬停。 使用以下方法:
$('#search-button').hover(function () {
$('#search-text').show();
});
这可能有效
$('#search-text').hide(); //on DOM Load hide the element
$('#search-button').mouseover(function()
{
$('#search-text').show(); //When mouse enters the element, then show the textbox input
});
$('#search-button').hover(function () {
$('#search-text').show();
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<input type="button" id="search-button" value="search"/>
<input type="text" id="search-text" style="display:none;"/>
相关文章:
- 如何使用提交按钮搜索表中的记录
- Magento上的搜索按钮损坏
- 如何在单击按钮时使用instantsearch.js启动搜索
- 搜索按钮谷歌地图在我的vf页面上不起作用
- jqgridnavgrid在搜索按钮和自定义按钮之后添加按钮
- 一页主题搜索/用下一个按钮突出显示文本
- 如何在第一次单击后禁用搜索按钮,直到结果来自服务器
- 将搜索按钮从一个站点复制到另一个站点:此搜索按钮如何工作,以及如何重现其操作
- 如何使用带有搜索按钮的Google Places API
- 如何获取ExtJs 4.1.1中的搜索按钮
- 允许在表刷新后键入数据表搜索按钮
- 按enter键不会通过p:defaultCommand点击预期的搜索按钮
- jQuery:如何创建一个带有多个单选按钮的实时搜索表单
- jQuery在多个表中搜索文本,如果找到文本,则单击按钮
- jqGrid不显示搜索按钮
- 谷歌地图如何通过点击按钮搜索地点
- 在运行时按搜索按钮突出显示文本
- 如何显示弹出窗口以在使用纯 JavaScript 从 Web 服务器获取/请求数据时禁用搜索按钮
- 点击弹出窗口中的按钮搜索结果
- Ionic 2添加页面,按钮搜索页面没有任何作用