##HarmonyOS Next快速入门##HarmonyOS应用开发##教育##
通用事件分为以下几类:
点击事件
.onClick(() => {
// 处理点击事件逻辑
})
当手指或手写笔在组件上触碰时,会触发不同动作所对应的事件响应,包括按下(Down)、滑动(Move)、抬起(Up)事件:
onTouch(event: (event?: TouchEvent) => void)
焦点、焦点链和走焦
焦点态:用来指向当前获焦组件的样式。
获焦事件
.onFocus(() => {
// 处理获焦事件逻辑
})
失焦事件
.onBlur(() => {
// 处理失焦事件逻辑
})
气泡弹窗事件
.bindPopup(this.handlePopup, {
message: 'This is a popup with PopupOptions',
})
代码实例:UniversalEvents
@Entry
@Component
struct UniversalEvents {
@State message: string = 'UniversalEvents ';
@State count:number=0;
@State eventMessage:string="Events Message";
@State phone:string='';
@State handlePopup:boolean=false;
build() {
Column({space:10}) {
Text(this.message)
.fontSize(30)
.fontWeight(FontWeight.Bold)
Text(`click time: ${this.count}`).onClick(()=>{
this.count=this.count+1
})
TextInput({placeholder:'Focus Event'})
.onFocus(()=>{
this.eventMessage="I do focus event---"
})
.onBlur(()=>{
this.eventMessage="I do lost focus event***"
})
Text(this.eventMessage)
TextInput({placeholder:'please input phone'})
.type(InputType.Number)
.onChange((value:string)=>{
this.phone=value
})
.onFocus(()=>{
this.handlePopup=false;
})
.onBlur(()=>{
if(this.phone==''){
//Tell the user that the phone number cannot be empty
this.handlePopup=true;
}
})
.bindPopup(this.handlePopup,{
message:"Mobile number cannot be empty"
})
}
.height('100%')
.width('100%')
}
}
原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。
如有侵权,请联系 cloudcommunity@tencent.com 删除。
原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。
如有侵权,请联系 cloudcommunity@tencent.com 删除。