卡卡LL
卡卡LL
  • 发布:2021-12-07 19:02
  • 更新:2021-12-07 19:02
  • 阅读:331

点击其他地方,input自动获取焦点

分类:uni-app

uni app开发app

form表单,左边是文字,右边是输入框

希望实现点击左边的文字,右侧的input能自动获取焦点,弹起键盘

每一行都是一个组件

<!-- #ifndef MP -->
<view @click="findInputFocus()" class="cu-item">
<!-- #endif -->
<!-- #ifdef MP -->
<view class="cu-item">
<!-- #endif -->
<view class="content margin-right-lg">
<text v-if="required" class=" text-red margin-right-xs">*</text>
<text class="text-grey">{{ title }}</text>
</view>
<view class="action text-cut text-right text-cut" style="max-width: 200px">
<slot></slot>
</view>
</view>

const helper = {
findInput:function findInput(vm){
let name;
// #ifdef APP-PLUS
name = vm.type.toLowerCase()
// #endif
// #ifdef H5
name = vm.tagName.toLowerCase()
// #endif
if(name == 'input' || name == 'textarea'){
return vm;
}
for(let i = 0;i<vm.children.length;i++){
let temp = findInput(vm.children[i]);
if(temp)
return temp;
}
}
}

findInputFocus(){
let input = helper.findInput(this.$el);
if(input){
// #ifdef H5
input.focus();
// #endif
}
}

找到input后应该如何让他获取焦点

2021-12-07 19:02 负责人:无 分享
已邀请:

该问题目前已经被锁定, 无法添加新回复