1200字范文,内容丰富有趣,写作的好帮手!
1200字范文 > html点击文本框唤醒手机键盘 html移动应用 input 标签 清除按钮功能如何实现(不

html点击文本框唤醒手机键盘 html移动应用 input 标签 清除按钮功能如何实现(不

时间:2021-11-23 13:11:55

相关推荐

html点击文本框唤醒手机键盘 html移动应用 input 标签 清除按钮功能如何实现(不

有个需求是:输入框有文本的时候就显示清除按钮,没有文本则隐藏清除按钮,点击清除按钮不能影响键盘弹出的状态。

网上有css实现自动显示和隐藏清除按钮的方案,但是考虑到兼容性,我们还是使用js来实现。

css

body{

background: #eee;

}

form{

margin: 30px 0;

position: relative;

}

#keyword{

height: 90px;

font-size: 60px;

line-height: 90px;

width: 300px;

}

#clear{

color: red;

width: 90px;

height: 90px;

line-height: 90px;

text-align: center;

position: absolute;

top: 0;

left: 210px;

visibility:hidden;

}

html

js

var keyword = document.getElementById('keyword'),

clear=document.getElementById('clear'),

autoShow=function () {

clear.style.display=keyword.value.length>0?'block':'none';

clear.style.visibility=keyword.value.length>0?'visible':'hidden';

};

keyword.οninput=autoShow;

clear.οnmοusedοwn=function (e) {

keyword.value = '';

autoShow();

keyword.focus();

e.preventDefault();

e.stopPropagation();

return false;

};

html点击文本框唤醒手机键盘 html移动应用 input 标签 清除按钮功能如何实现(不触发键盘)...

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。