在input裏面設置focusapp
<input type="text" focus="{{inputShowed}}" />
左邊的是input沒有獲取焦點事件,也沒有鍵盤彈出。框架
// 搜索框狀態 inputShowed: false,
右邊的是input獲取焦點事件,默認有鍵盤彈出。xss
// 搜索框狀態 inputShowed: true,
wxmlide
<view class="weui-search-bar"> <view class="weui-search-bar__form"> <view class="weui-search-bar__box"> <icon class="weui-icon-search_in-box" type="search" size="14"></icon> <input type="text" class="weui-search-bar__input" placeholder="滬A6789" maxlength='10' value="{{inputVal}}" focus="{{inputShowed}}" /> </view> </view> </view>
wxss:(引入了全局框架WeUI,可省略不寫)ui
/* 搜索 */ .weui-search-bar__input{ height: 72rpx; } .weui-icon-search_in-box{ top:22rpx; } .weui-search-bar__cancel-btn{ line-height:70rpx; } .weui-icon-clear{ top:4rpx; }
js:code
var app = getApp() Page({ data: { // 搜索框狀態 inputShowed: false, // 搜索框值 inputVal: "", }, onLoad: function () { }, });
原文做者:祈澈姑娘orm
加入qq羣聊來問我:473819131.xml