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后应该如何让他获取焦点
0 个回复