首页 技术 正文
技术 2022年11月11日
0 收藏 564 点赞 3,789 浏览 1650 个字

目前很多手机app或者一些webapp,搜索栏基本采用跳窗口的搜索方式

如何让你的webapp也能跳窗口搜索

如何让你的webapp也能跳窗口搜索

怎么做

实现方式:

1、在触发外层的input的时候打开个modal层,默认打开该modal层的时候就触发了moda里面的input的focus事件

2、将软键盘变成搜索字样,在web中你可能会觉得input type=”search”就会很自然的换行变成了搜索两个字,其实不然,你需要用form去裹着

<form method="post" id="form" action="#">
<div class="sosoModal_in"> <input type="text" id="searchKeyValue" ><span>取消</span> </div>
</form>

3、如果你不需要form提交,而是想通过ajax去异步的提交搜索,你需要阻止掉form的默认行为,return false;

4、监听keycode=13的事件,处理搜索逻辑,在modal层中显示搜索数据

5、modal层的取消按钮监听点击事件,点击后关闭该modal层,退回到列表页。

html的结构应该是类似这样的:

<!--搜索模态框-->
<div class="sosoModal">
<form method="post" id="form" action="#">
<div class="sosoModal_in">
<input type="text" placeholder="搜索" id="searchKeyValue" ><span>取消</span>
</div>
</form>
<div class="list_con searchResultCon">
<!--搜索结果,item-->
</div>
<div id="pageCon"></div>
</div>
<!--搜索框-->
<div class="search_wrap">
<input type="text" id="search_txt" placeholder="输入搜索关键字..." />
</div>

js简单的写应该是类似这样的

                        //打开modal
$("#search_txt").focus(function(){
$(".sosoModal").fadeIn(400);
$(".sosoModal_in input").focus();
});
//监听取消
$(".sosoModal span").on('click',function(){
$('.sosoModal').fadeOut(400);
$('#searchKeyValue').val()!=''? $('#searchKeyValue').val(""):"";
});
//监听回车搜索键
var searchTxt = $('#searchKeyValue');
$(window).keydown(function(e){
if(e.keyCode==13){//替换列表数据
if (searchTxt.val() && searchTxt.val().length>0){
g_sqlwhere = " w.WFNAME like '%"+searchTxt.val()+"%' or w.STARTOR like '%"+searchTxt.val()+"%' or w.STATIME like '%"+searchTxt.val()+"%' or w.SUBJECT like '%"+searchTxt.val()+"%' " ;
}
else{
g_sqlwhere = "";
}
                       //显示搜索结果
wf.init();
//关闭当前modal
$('.sosoModal').fadeOut(400);
                        //搜索栏值置空
searchTxt.val()!=""?searchTxt.val(""):"";
//阻止默认事件
return false;
}
});

关于为什么app都采用这样方式去搜索,我想应该是为了更好的显示出搜索结果,也是为了更好的用户体验  

  

上一篇: node了解
相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:8,961
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,485
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,330
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,113
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,746
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,780