p4.component.ts 1.14 KB
Newer Older
李彥志's avatar
李彥志 committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
import { Component, OnInit } from '@angular/core';

@Component({
  selector: 'app-p4',
  templateUrl: './p4.component.html',
  styleUrls: ['./p4.component.css']
})
export class P4Component implements OnInit {

  number = '';
  value2: any;

  addNumber(inputRef: HTMLInputElement): void {
    console.log(inputRef.value);
    inputRef.value = '';

李彥志's avatar
李彥志 committed
17
    this.value2 = new Number(inputRef.value);
李彥志's avatar
李彥志 committed
18 19

    if (
李彥志's avatar
李彥志 committed
20
      this.value2 > 0
李彥志's avatar
李彥志 committed
21
    ) {
李彥志's avatar
李彥志 committed
22
      alert('輸入正確');
李彥志's avatar
李彥志 committed
23
    } else {
李彥志's avatar
李彥志 committed
24
    alert('請輸入大於0的數字');
李彥志's avatar
李彥志 committed
25 26 27
    }
  }

李彥志's avatar
李彥志 committed
28 29 30 31
  addNumber2(inputRef: HTMLInputElement): void {
    console.log(inputRef.value);
    inputRef.value = '';

32
    this.value2 = new Number(inputRef.value);
李彥志's avatar
李彥志 committed
33 34

    if (
35
      this.value2 !== Number
李彥志's avatar
李彥志 committed
36
    ) {
李彥志's avatar
李彥志 committed
37
      alert('只能輸入數字');
李彥志's avatar
李彥志 committed
38
    } else {
李彥志's avatar
李彥志 committed
39
    alert('輸入正確');
李彥志's avatar
李彥志 committed
40 41 42
    }
  }

李彥志's avatar
李彥志 committed
43 44 45 46 47 48 49 50 51
  addNumber3(inputRef: HTMLInputElement): void {
    console.log(inputRef.value);
    inputRef.value = '';

    this.value2 = new Number(inputRef.value);

    if (
      this.value2 !== Number
    ) {
李彥志's avatar
李彥志 committed
52
      alert('欄位只能輸入英文兩碼 + 數字三碼');
李彥志's avatar
李彥志 committed
53 54 55 56
    } else {
    alert('輸入正確');
    }
  }
李彥志's avatar
李彥志 committed
57 58 59 60 61 62 63 64


  constructor() { }

  ngOnInit() {
  }

}