我想知道是否有人可以帮助我。我想创建一个仅接受数字的文本框用户控件。
谢谢。
答案 0 :(得分:1)
使用HTML
<input (keypress)="onlyNumberKey($event)">
使用HTML和Jquery
HTML
onlyNumberKey(event) {
return (event.charCode === 8 || event.charCode == 0) ? null : event.charCode >= 48 && event.charCode <= 57;
}
jQuery
constructor(){
this.data = of({
"projectdata": {data: "data"}
});
}
private paramsSubject = new BehaviorSubject(this.testParams);
private _testParams: {};
params = this.paramsSubject.asObservable();
get testParams() {
return this._testParams;
}
set testParams(newParams: any) {
this._testParams = newParams;
this.paramsSubject.next(newParams);
}