让某个输入框获取焦点可以使用sendEventByKey方法像该组件发送一个点击事件,以下是简单示例,点击获取验证码按钮,呼出键盘:@Entry @Component struct TextInputExample { @State text: string = '' controller: TextInputController = new TextInputController() build() { Column() { Row() { TextInput({ text: this.text, placeholder: '请输入用户名', controller: this.controller }) .height(40) .margin(20) .fontSize(14) .width('90%') .id('t1') } Row() { TextInput({ placeholder: '请输入密码' }) .height(40) .margin(20) .type(InputType.Number) .maxLength(9) .width('60%') .id('t2') Button('获取验证码') .onClick(() => { /** * id:要触发事件的组件的id * params: 事件参数,无参数传空字符串 */ sendEventByKey('t2', 10, ''); }) .width('30%') } .justifyContent(FlexAlign.SpaceBetween) .width('100%') } } }参考文档:https://developer.huawei.com/consumer/cn/doc/harmonyos-references-V5/ts-universal-attributes-component-id-V5
让某个输入框获取焦点可以使用sendEventByKey方法像该组件发送一个点击事件,以下是简单示例,点击获取验证码按钮,呼出键盘:
参考文档:https://developer.huawei.com/consumer/cn/doc/harmonyos-references-V5/ts-universal-attributes-component-id-V5