h5页面input输入框手机键盘没有“搜索”按钮;隐藏自带的清除、搜索图标;点搜索后键盘无法自动收回。

场景:在页面中,存在一个input输入框,当用户在其上点击并试图输入时,弹出的键盘并未配备“搜索”和“确认”按钮,这导致用户无法顺利地触发搜索操作。

效果如下:

修改方式如下:

<form action="javascript:return true;">
    <input type="search" name="search" ref="searchInput"/>
</form>

  

不加form标签包着的话ios系统不会生效

特别注意:在将输入框的type属性设置为"search"后,移动设备上会显示一个默认的X图标,而在iOS系统上还会出现放大镜图标。因此,为了确保最佳的视觉效果和用户体验,我们需要结合以下样式:

input[type="search"] {
  -webkit-appearance:none;
}
input[type="search"]::-webkit-search-decoration {  
  display: none;  
}
input[type="search"]::-webkit-search-cancel-button {
  display: none;
}

当搜索触发后,键盘无法自动收回,因此我们需要触发失焦事件来手动关闭键盘。

this.$refs.searchInput.blur()

 

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
感谢您的提问!以下是 Taro Ui Vue3 中防止 H5 安卓机在输入框弹窗键盘时将页面顶上去的一个例子: ``` <template> <div> <AtButton type="primary" @click="toggleModal">弹出模态框</AtButton> <AtModal :isOpened="isOpened" @close="handleClose"> <AtModalHeader>标题</AtModalHeader> <AtModalContent> <div class="input-wrapper"> <input type="text" placeholder="请输入内容" @focus="handleFocus" @blur="handleBlur"> </div> </AtModalContent> <AtModalAction> <Button onClick="handleClose">取消</Button> <Button onClick="handleClose">确定</Button> </AtModalAction> </AtModal> </div> </template> <script> import { defineComponent, onMounted, ref } from 'vue' import { AtButton, AtModal, AtModalHeader, AtModalContent, AtModalAction } from 'taro-ui-vue3' export default defineComponent({ name: 'ModalExample', components: { AtButton, AtModal, AtModalHeader, AtModalContent, AtModalAction, }, setup() { const isOpened = ref(false) const toggleModal = () => { isOpened.value = !isOpened.value } const handleClose = () => { isOpened.value = false } const handleFocus = () => { if (/Android/gi.test(navigator.userAgent)) { setTimeout(() => { document.activeElement.scrollIntoViewIfNeeded() }, 100) } } const handleBlur = () => { if (/Android/gi.test(navigator.userAgent)) { setTimeout(() => { document.activeElement.scrollIntoViewIfNeeded() }, 100) } } onMounted(() => { if (/Android/gi.test(navigator.userAgent)) { const height = window.innerHeight const timer = setInterval(() => { if (window.innerHeight !== height) { document.body.style.height = window.innerHeight + 'px' height = window.innerHeight } }, 100) return () => clearInterval(timer) } }) return { isOpened, toggleModal, handleClose, handleFocus, handleBlur, } }, }) </script> <style scoped> .input-wrapper { padding: 20px; } input { width: 100%; height: 50px; font-size: 18px; border: none; border-bottom: 1px solid #ccc; outline: none; } </style> ``` 这个例子中,我们使用了 Taro Ui Vue3 的 AtModal 组件,同时在输入框的 focus 和 blur 事件中,通过调用 `scrollIntoViewIfNeeded()` 方法,将输入框滚动到可视区域内。同时,在组件挂载时,我们通过监听窗口大小的变化,动态设置 body 的高度,以防止页面出现滚动条。希望这个例子能够帮到您!

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

唐小亭

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值