VueJS/iView的Input输入框获得焦点(点击或者选择后)自动全选全部文本

2022-04-25 1311点热度 0人点赞 0条评论

需求

iView的Input输入框,希望用户点到输入框的时候,自动全选输入框里内容,方便用户直接输入新的文字内容。

实现

可以使用@on-focus来实现,给on-focus绑定方法,$event.target.select()来全选内容,如下:

<i-input v-model="cg.inSh" type="text" @on-focus="$event.target.select()" style="width: 250px;" :maxlength="50">
    <span slot="prepend" class="red-star">对校外服务收入 </span>
    <span slot="append">元</span>
</i-input>

如果是Vue

<input @focus="$event.target.select()">

如果在Component下

<my-component @focus.native="$event.target.select()"></my-component>

 

admin

这个人很懒,什么都没留下

文章评论

您需要 登录 之后才可以评论