选中input框,隐藏输入法键盘
作者:程序员11 时间:2023-05-16 人气:424 QQ交流群\邮箱:1003265987@qq.com
选中input框,隐藏输入法键盘
要展示的内容
1、加readonly,此方法不能type,只能看,不适合我的业务场景。
<input type="text" readonly />
2、此方法,我这边测试,在手机和终端设备上,虽然不弹出键盘,但是既不能type,也没有焦点。
$("#box").focus(function(){
document.activeElement.blur();
})真实的方法:
这是react+mobx的项目,用readOnly属性和onFocus事件就解决了。键盘隐藏了,还有焦点光标,并且能type。
<input
autoFocus
readOnly={readonly}
placeholder="请输入"
value={price}
onFocus={(event: React.FocusEvent<HTMLInputElement>) => onFocus()}
onChange={(event: React.ChangeEvent<HTMLInputElement>) => setPrice(event.target.value)}
/>@action onFocus = () => {
this.readonly = true;
setTimeout(() => {
this.readonly = false;
}, 200);
}
温馨提示:
欢迎阅读本文章,觉得有用就多来支持一下,没有能帮到您,还有很多文章,希望有一天能帮到您。
HTML5-热门文章
活跃用户












