[LayaAir3]textinput中文字改变后,如何执行一个函数
最近想做一个打字软件,界面上方是范文,下面是一个 textinput 组件,用户可以在此输入文字,现在遇到的问题是,这个输入框中的文字改变后,如何及时侦测到,从而能执行一些动作,参考了网上一些教程,没有效果啊,不知哪里问题,望指教。下面代码是创建一个输入框 ,这个是对的,但侦测 不到文字的变化
onEnable(): void {
let txt = new Laya.TextInput();
// 添加到舞台
Laya.stage.addChild(txt);
txt.pos(Laya.stage.width >> 1, Laya.stage.height >> 1); //位置
txt.size(500, 30); //大小
txt.pivot(txt.width/2, txt.height/2); //轴心点
txt.text = "大家好"; //文本内容
txt.wordWrap = true; //自动换行
txt.on(Laya.Event.CHANGE, this, this.onTextChange);
}
onTextChange(){
console.log("this")
}
onEnable(): void {
let txt = new Laya.TextInput();
// 添加到舞台
Laya.stage.addChild(txt);
txt.pos(Laya.stage.width >> 1, Laya.stage.height >> 1); //位置
txt.size(500, 30); //大小
txt.pivot(txt.width/2, txt.height/2); //轴心点
txt.text = "大家好"; //文本内容
txt.wordWrap = true; //自动换行
txt.on(Laya.Event.CHANGE, this, this.onTextChange);
}
onTextChange(){
console.log("this")
}
要回复问题请先登录
1 个回复
LayaAir小牛
赞同来自:
您好,图中为textinput部分源码,textinput没有CHANGE这个事件。建议将 txt.on(Laya.Event.CHANGE, this, this.onTextChange); 中的CHANGE改为INPUT,可能会解决您的问题。实测修改文本后会触发事件侦听函数