input/textarea 输入框点击有边框解决方法

input/textarea 输入框点击出现类似以下的默认边框

默认边框

第一种方法(直接添加样式)

 input{
   outline: none;
 }

第二种方法(控制聚焦时不出现边框)

input:focus{
   outline: none;
 }
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
这个问题可能是由于键盘弹起时导致输入框被顶起,但是键盘隐藏时输入框没有重新布局,导致留下了一个空白的边框。为了解决这个问题,你可以尝试以下几个方法: 1. 使用 `@focus` 和 `@blur` 事件来监听输入框的焦点状态,当输入框失去焦点时重新布局输入框,例如: ```html <template> <div> <textarea ref="input" v-model="message" @focus="onFocus" @blur="onBlur"></textarea> <button @click="sendMessage">发送</button> </div> </template> <script> export default { data() { return { message: '', originalHeight: 0 // 记录输入框的原始高度 } }, methods: { onFocus() { this.originalHeight = this.$refs.input.clientHeight }, onBlur() { this.$refs.input.style.height = this.originalHeight + 'px' }, sendMessage() { // 发送消息 } } } </script> <style scoped> textarea { box-sizing: border-box; width: 100%; border: 1px solid #ccc; padding: 10px; font-size: 16px; line-height: 1.5; resize: none; } </style> ``` 2. 使用 `uni.hideKeyboard()` 方法来隐藏键盘,并在隐藏键盘后重新布局输入框,例如: ```html <template> <div> <textarea ref="input" v-model="message" @keydown.enter="onEnter"></textarea> <button @click="sendMessage">发送</button> </div> </template> <script> export default { data() { return { message: '', originalHeight: 0 // 记录输入框的原始高度 } }, methods: { onEnter() { uni.hideKeyboard({ complete: () => { this.$refs.input.style.height = this.originalHeight + 'px' } }) }, sendMessage() { // 发送消息 } } } </script> <style scoped> textarea { box-sizing: border-box; width: 100%; border: 1px solid #ccc; padding: 10px; font-size: 16px; line-height: 1.5; resize: none; } </style> ``` 以上两种方法都可以解决输入框隐藏后留下空白边框的问题,你可以根据自己的需求选择其中一种实现方式。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值