如何实现一个input搜索框?

小程序 文章 2021-03-17 14:01 506 0 全屏看文

AI助手支持GPT4.0

如何实现一个input搜索框?How to implement an input search box?

如何实现一个input搜索框?

这是默认样式

这是聚焦后显示

这是输入内容

看着很简单对吧,我一开始也是这么想的,结果当我做起来我发现.....这tm就离谱

先说下我怎么实现的,元素是input,中间的图片用背景图,搜索岗位是placeholder,

当focus时,我给input元素添加类,然后让text-align: left;,background-image:none;

当blur时,我再判断框内value是否不为空,如果为空,再把那个类去掉,他就会恢复默认样式

:注因为我用的iphone,所以我自己开发调试都是在ios的微信上跑的

结果......

IOS 上,focus 要等软键盘抬起了才触发,就是那光标已经在那闪了,但是我的事件没有触发,导致我用bindtap绑定了点击事件

我想这下没问题了吧....

结果....

IOS上,有时候不聚焦!!!!!, 明明点击了input,事件都触发了,类都添加上去了,结果没有软键盘抬起...

于是乎:我加了这么一行

      this.setData({

        isFocus: true

      });

<input focus="{{isFocus}}" ...省略/>

强制聚焦

这下没问题了吧,虽然有点延迟,有点卡顿的效果,但勉强算是实现了。。

准备提交发布审核:策划带着bug来了......

聚焦了,图标没有消失,文字没有向左对其...

还有这个

还有这个


第一次做微信小程序,救命阿救命阿....................

This is the default style. This is the display after focusing. This is the input content. It looks very simple, right? I thought so at the beginning. As a result, when I started to do it, I found that... This TM is ridiculous. First, let's talk about how I implemented it. The element is input, the image in the middle uses the background image, and the search position is placeholder. When focusing, I added a class to the input element, and then let text align: left; ,background- image:none; When "blue", I will judge whether the value in the box is not empty. If it is empty, I will remove that class, and it will return to the default style: Note: because I use the iPhone, so my own development and debugging are all the results of running on IOS wechat... IOS, focus I have to wait for the soft keyboard to be raised before triggering. That is, the cursor has already flashed there, but my event has not been triggered. As a result, I used bindtap to bind the click event. I think it's ok now. As a result, sometimes it doesn't focus on IOS!!!!!, When you click input, the events are triggered, the classes are added, but no soft keyboard is raised... So: I added this line this.setData ({isfocus: true}); < input focus = {isfocus} "... Omitting / > forcing focus is OK. Although it's a little delayed and a little stuck, it's barely realized.. Ready to submit for release review: the plan came with bugs... Focused, the icon didn't disappear, the text didn't turn left to it... And this and this first time to do wechat applet, help, help

回答:

小胡:

或许可以用伪类来实现

asuka:还请细说

-EOF-

AI助手支持GPT4.0


国内超级便宜服务器

摸鱼人热门新闻聚合

钻级赞助商 我要加入

开发者在线工具

第三方支付技术请加QQ群

相关文章
推荐组件一直没有积分
scroll-view 无法横向显示?
第三方应用开发调用企业微信发送应用消息(任务卡片),如何支持id转义?
请问下 腾迅文档小程序 公众号文章是怎么实现 点右上角三个点可以在腾讯文档中打开和保存公众号文章?
微信开发者工具中style里的width要接接口数据什么做?
随便看看
企业微信通讯录账号被管理员误/恶意删除,怎么办? 8530
问题? 8251
如何快速搭建抽奖助手小程序(无需代码知识) 5310
许涛 大哥在吗, 要解冻小程序的时候提示信息主体不一致, 能帮忙看下吗? 6577
小程序搜一搜全称搜索不显示 麻烦解决一下!谢谢 5865
我的小程序广告收款主体是个体工商户,每个月邮寄两次发票很是麻烦,我年底的时候打包邮寄一次可以么? 5526
如何解决渲染层网络错误Failed to load media? 16768
小程序找号找回 释放昵称? 2783
我的小程序广告主收入5301,实际进账4406,是怎么回事呀? 2654
删除部分微信用户个人数据的通知,怎么删除? 5830