在文本框中更改输入时调用函数?
我正在尝试创建一个按钮,当用户名和密码字段都使用某种输入(IE;用户名或密码文本框都不为空)输入时,该按钮会改变颜色
I'm trying to create a button that changes color when username and password fields have both been entered with some sort of input (IE; neither username or password text boxes are empty)
在 NativeScript 中更改文本框的输入时,有没有办法让函数触发?我曾在 NativeScript slack 和其他网站上询问过,但似乎从未得到答复.
Is there a way I can get a function to trigger when input of a text box is changed in NativeScript? I've asked at the NativeScript slack, among other sites but I don't seem to get a reply ever.
我认为这是一个相对简单的请求,尤其是当我使用 vanilla JS 时.它肯定比使用 Angular 或 Vue 等框架更简单吗?
I thought this was a relatively simple request, especially when I'm using vanilla JS. Surely it must be simpler than using a framework such as Angular or Vue?
我不想使用框架,我正在寻找一种使用纯 JS 实现此目的的方法.我尝试了什么?我试过 onChange=""
, textChange=""
, change=""
但似乎都不起作用.
I do not want to use a framework, I am looking for a way to do this with plain JS. What have I tried? I've tried onChange=""
, textChange=""
, change=""
but none seem to work.
如果你使用的是没有任何框架的纯 JavaScript/TypeScript,那么你必须在 loaded
之后添加你的 textChange
监听器代码>事件.
If you are using plain JavaScript / TypeScript without any framework, then you must add your textChange
listener after loaded
event.
XML
<TextField loaded="onTextFieldLoaded"></TextField>
JS
function onTextFieldLoaded(args) {
const textField = args.object;
textField.off("loaded");
textField.on("textChange", onTextChange);
}
function onTextChange(args) {
console.log("Changed: " + args.value);
}