[英]I want to Create textbox which allows only numbers. How can I do that with Typescript in aurelia?
I want to enter only numbers in textbox so i have added oninput but i want to create using bindableproperty. 我只想在文本框中输入数字,所以我添加了oninput但我想使用bindableproperty创建。 I don't have idea how to do that. 我不知道该怎么做。 Please suggest me ? 请建议我?
<template bindable="">
<input style="
box-sizing: border-box;"
maxlength="10" ;
oninput="this.value = this.value.replace(/[^0-9.]/g, '').replace(/(\..*)\./g, '$1');" />
</template>;
import { bindable } from 'aurelia-framework';
export class textbox {
constructor() {
}
}
<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);
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.