【问题标题】:I want to Create textbox which allows only numbers. How can I do that with Typescript in aurelia?我想创建只允许数字的文本框。我如何在 aurelia 中使用 Typescript 来做到这一点?
【发布时间】:2019-09-11 15:15:29
【问题描述】:

我只想在文本框中输入数字,所以我添加了 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() {
  }
}

app.html

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

app.ts

export class App {
}

【问题讨论】:

    标签: typescript textbox aurelia


    【解决方案1】:
    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);
    }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-11-22
      • 2021-02-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多