前言
在H5开发中,经常会开发搜索功能,商品列表、订单列表、客户列表等等,都需要搜索,所以程序猿(程序媛)们都会遇到这样的需求,点击搜索input时,弹出的键盘,有“搜索”按钮,点击搜索调用接口搜索。今天就来讲讲怎么搞定这个需求。
html代码
<form action="javascript:;" id="searchFrom" onsubmit="searchList">
  <input type="search" value="" placeholder="搜索Javan的博客" />
</form>
js代码
- 元素绑定方法调用
function searchList(){
  // do something
}
- jquery监听
$('#searchFrom').bind('submit', function () {
  // do something
});
注意事项
- action="javascript:;"这里的作用是,防止页面刷新,如果不写,页面会刷新
- type="search""input的类型需要是search
- input输入框必须放到form表单中
- 这样写input框输入值后,会有清除按钮,需要改变样式,或者去除,请看下方代码
input[type=search]::-webkit-search-cancel-button{
    -webkit-appearance: none; // 此处只是去掉默认的小×
}
自定义样式
input[type=search]::-webkit-search-cancel-button{
    -webkit-appearance: none;
    position: relative;
    height: 20px;
    width: 20px;
    border-radius: 50%;
    background-color: #EBEBEB;
}
input[type=search]::-webkit-search-cancel-button:after{
    position: absolute;
    content: 'x';
    left: 25%;
    top: -12%;
    font-size: 20px;
    color: #fff;
}
公告
以后每月5、15、25号更新原创文章,内容不限,喜欢小编Javan的博客的可以点击关注,也可在下方评论留言,你喜欢什么内容,小编根据大家喜欢的内容尝试更新
点击查看更多内容
					3人点赞
										
				 评论
				共同学习,写下你的评论
评论加载中...
作者其他优质文章
					正在加载中
				
			感谢您的支持,我会继续努力的~
		扫码打赏,你说多少就多少
		赞赏金额会直接到老师账户
		支付方式
		打开微信扫一扫,即可进行扫码打赏哦
	 
                 
            
 
			 
					 
					