- <input class="fr fontSize30 colorBlack uni-input"
- type="inputType"
- value="value"
- placeholder="placeholder"
- maxlength="maxlength"
- disabled="disabled"
@input="input"
@blur="searchEntBlur"
@focus="inputFocus"
cursor="2"
/>
想在input获取焦点时,光标移到最后一位,设置cursor的值,感觉没有生效
![a***@163.com](https://img-cdn-tc.dcloud.net.cn/account/identicon/51f16881a3ce7cf317494ea6ada45ee8.png)
- 发布:2019-02-21 11:32
- 更新:2024-04-28 11:22
- 阅读:6697
![迟海](http://img-cdn-tc.dcloud.net.cn/uploads/avatar/000/21/22/66_avatar_mid.jpg?v=0)
迟海 - 美丽总是稍纵即逝,但瞬间即永恒
这个cursor无效的问题,在h5模式应该是type的原因,我试了在type是number或digit时cursor就无效,text、tel、idcard就有效
![3***@qq.com](https://img-cdn-tc.dcloud.net.cn/account/identicon/ea5352a1cb889e23b38cc098cc99458b.png)
解决了
<input type="number" class="newinput" :value="item.value" maxlength="1" :focus="item.myfocus" v-for="(item,index) in inputlist" :key="index"/>
inputlist:[
{
value:'',
myfocus:true
},
{
value:'',
myfocus:false
},
{
value:'',
myfocus:false
}
],
把focus写入数据中,循环出来后,焦点自动出现在第一个位置。
![喜欢技术的前端](http://img-cdn-tc.dcloud.net.cn/uploads/avatar/000/62/23/57_avatar_mid.jpg?v=0)
喜欢技术的前端 - QQ---445849201
指定光标的位置,可以参考
<template>
<view class="content">
<input type="text" class="input" @blur="blurFn" @focus="focusFn" :focus="focus" :cursor="cursor" placeholder="请输入">
<button @click="clickFn" style="margin-top: 30px;">focus</button>
</view>
</template>
<script>
export default {
data() {
return {
cursor:0,
focus:false
};
},
onReady() {
},
methods: {
blurFn(){
this.focus = false
this.cursor = 0
},
focusFn(e){
// this.cursor = 3
},
clickFn(){
this.focus = true
this.cursor = 2
},
}
};
</script>
<style scoped lang="scss">
.content {
padding: 0 20px;
.input{
padding: 30rpx 0;
}
}
</style>
1***@qq.com
牛逼!!!!
2021-10-20 20:10
1***@qq.com
微信小程序目前无效
2021-12-31 10:08