设置移动端的搜索键盘

本文介绍了一个基于HTML和JavaScript的简单搜索功能实现方法,包括如何响应键盘事件来触发搜索行为,并通过URL传递搜索参数。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
<meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no, minimal-ui"/>
<meta name="format-detection" content="telephone=no, email=no"/>
<style>
::-webkit-search-cancel-button { display: none; }
</style>
<script type="text/javascript">
function seacherKeyDown(e){
//搜索判断是移动端还是pc
var e = e || window.event;

if(e.keyCode == 13){
var leftVal = $.trim($("#js_id_seach").val());
if(leftVal==0 || leftVal=='搜索关键字'){
$("#js_id_seach").focus();
}else{
window.location.href='/was5/web/search?channelid=294808&searchword='+encodeURIComponent(leftVal);
}
}
}
</script>
</head>
<body>
<form action="#" target="testif">
<input type="search" placeholder="搜医生、搜疾病" onkeypress="seacherKeyDown(event)"
id="js_id_seach" style="width: 300px;height: 50px;"/>
<iframe name="testif" style="display: none;"></iframe>
</form>

</body>
</html>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值