typescript - 我想创建只允许数字的文本框。我如何在 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>
应用程序.ts
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);
}
}
推荐阅读
- python - [子函数]TypeError:不支持的操作数类型-:'str'和'float'
- gcc - f951:错误:无法识别的命令行选项“-auxbase”
- c++ - 逗号运算符的右操作数无效 -wunused 变量
- pandas - 在python中按中位数排名
- tensorflow - 如何使用 tensorflow 微调训练好的模型和保存的模型?
- python - 如何在 django 的媒体文件夹中创建和保存 csv 文件?
- javascript - NGL 查看器 - 无法导入模块
- asp.net - 使用角度刷新 ASP .NET 中的路由时不加载 HTML
- r - 手动安装 R 包时权限被拒绝
- haskell - groupBy 的奇怪行为