先看下效果
点击按钮选中input的内容,使用 focus 配合 selection-start和selection-end实现
//html
<view class="pickbox">
<input class="uni-input" type="text" v-model="value" :focus="renameFocus" :selection-start="start"
:selection-end="end" @blur="bindblur"/>
<button type="default" @click='pitch'>选中</button>
</view>
//js
data(){
value:'选中输入框内容',
renameFocus:false,
start:-1,
end:-1
},
pitch(){
this.renameFocus=true
this.start=0
this.end=this.value.toString().length
},
bindblur(){
this.renameFocus= false
this.start= -1
this.end= -1
},
如果想点击i