我想创建只允许数字的文本框.我怎样才能在Aurelia中使用Typescript做到这一点?



我只想在文本框中输入数字,所以我添加了 oninput,但我想使用 bindableproperty 创建。我不知道该怎么做。请建议我 ?

文本框.html

<template bindable="">
<input style="
box-sizing: border-box;"
maxlength="10" ;
oninput="this.value = this.value.replace(/[^0-9.]/g, '').replace(/(..*)./g, '$1');" />
</template>;   

文本框.ts

import { bindable } from 'aurelia-framework';
export class textbox {
constructor() {
}
}

应用.html

<template bindable="">
<require from="./components/textbox.html"></require>
<textbox></textbox>
</template>

应用程序

export class App {
}
I am just giving the idea, might be helpful:
In Html you may use  
(keyup)="methodName($event.targer.value)"  event.

In you ts file you may use:
bindedTextareaProperty;
methodName(event) {
if(isNumber(event){
} else {
// you may the value of last index
bindedTextareaProperty.slice(0, bindedTextareaProperty.length -1);
}
}

相关内容

最新更新