简体   繁体   English

我想创建仅允许数字的文本框。 如何使用aurelia中的Typescript做到这一点?

[英]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 ? 请建议我?

textbox.html textbox.html

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

textbox.ts textbox.ts

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

app.html app.html

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

app.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);
}
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 我想在文本框中自动添加破折号 (-)。 如何在 aurelia typescript 应用程序中执行此操作? - I want to automatically add dashes (-) in a textbox. How can I do this in an aurelia typescript application? 我如何在 React 中制作一个只允许数字或空值的文本框,这会触发移动设备上的数字键盘? - How can I make a text box in React which allows only numbers or an empty value, which triggers the number keypad on mobile? 我正在尝试创建一个仅允许使用打字稿输入数字的文本框。 见下面的例子 - I am trying to create a text box which allows only numbers using typescripts. See below example 如何创建一个由 4 个数字组成的随机字符串,该字符串在我的打字稿列表中尚不存在? - How do I create a random string of 4 numbers which does not exist already in my list in typescript? 如何制作一个Typescript接口,该接口类型检查某些属性,但也允许任何属性? - How can I make a Typescript interface which type checks some properties, but also allows any prorperty? 如何创建一个定义 function 的接口,允许 TypeScript 中的任意数量的变量? - How do I create an interface defining a function, that allows for any number of variables in TypeScript? 如何在 TypeScript 中接受仅为 5 的倍数的数字? - How do I accept numbers that are only multiples of 5 in TypeScript? 如何在 Typescript 中创建一个只包含非空/未定义属性的对象? - How can i create an object in Typescript which contains only non null/undefined properties? 如何在Aurelia打字稿应用程序中使用mobile-detect.js? - How do I use mobile-detect.js in an Aurelia typescript app? Aurelia / Typescript-如何通过选择标签将对象绑定到变​​量 - Aurelia/Typescript - How do I bind an object to a variable thru select tag
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM