1.input最常用的type值是text,然而我们发现,在使用text的时候,唤出的键盘没有搜索按钮,解决方法如下:
//html
<input type="text" />
改为:
<form action="">
<input type="search" autocomplete="off">
</form>
这样写即可使键盘出现搜索按钮
2.在css中添加一行代码即可去掉默认的x
//css
input[type=search]::-webkit-search-cancel-button{
-webkit-appearance: none;
}
这是由css3提供
3.默认的enter键按下会有默认事件,如果输入为空会执行页面刷新,这里需要阻止默认事件
//js
$("#search_input").keydown(function (events) {
if (events.which == 13) {
events.preventDefault ? events.preventDefault() : (events.returnValue = false);
}
});