可以使用sendEventByKey使输入框触发点击事件。// Index.ets import promptAction from '@ohos.promptAction'; @Entry @Component struct Index { @State message: string = 'Hello World'; @State isBoolean: boolean = true; build() { Row() { Column() { Text(this.message) .id('1sa') .fontSize(50) .fontWeight(FontWeight.Bold) Button('我会获取焦点') .key('BBB') TextInput({ placeholder: 'AAA' }) .id('AAA') .type(InputType.Normal) Button('点击焦点转移') .onClick(() => { let res = focusControl.requestFocus('BBB'); if (res) { promptAction.showToast({ message: 'Request success' }); } else { promptAction.showToast({ message: 'Request failed' }); } }) Button('点击获取焦点') .onClick(() => { this.isBoolean = true; sendEventByKey('AAA', 10, ''); // 向id为"longClick"的组件发送点击事件 }) } .width('100%') } .height('100%') } }参考链接sendEventByKey
可以使用sendEventByKey使输入框触发点击事件。
参考链接
sendEventByKey