zoukankan      html  css  js  c++  java
  • 表单体温实时验证

    描述:用户填写完体温,需要实时验证体温是否合法,并给出提示

    <input class="weui-input" type="number" placeholder="请输入体温"

    [formControl]="temperatureInput" name="temperatureName"/>

    import {FormControl} from '@angular/forms';

    temperatureInput = new FormControl();

    this.temperature = this.temperatureInput.value; // 获取温度值

    this.temperatureInput.valueChanges

          .pipe(debounceTime(1000))

          .subscribe(v => {

            if (v < 35 || v > 45) { // 如果温度输入超出预期,则提示错误

              this.srv['warn']('温度填写有误', 3500);

              return this.temperatureInput.setValue('');

            }

            const str = v.toString();

            if (str.indexOf('.') > -1 && str.split('.')[1].length >= 2) {

              const val = parseFloat(v) - 0; // inputvalue值转换为浮点数;

              const txt = val.toFixed(1); // 当用户输入价格小数点超过2位数,强制变成小数点2

              this.temperatureInput.setValue(txt);

            } else {

              this.temperatureInput.setValue(v - 0);

            }

          });

  • 相关阅读:
    lambda表达式
    PAT 1071. Speech Patterns
    PAT 1070. Mooncake
    1069. The Black Hole of Numbers
    PAT 1068. Find More Coins
    背包问题(动态规划)
    PAT 1067. Sort with Swap(0,*)
    PAT 1066. Root of AVL Tree
    PAT 1065. A+B and C
    PAT 1064. Complete Binary Search Tree
  • 原文地址:https://www.cnblogs.com/boreguo/p/12461135.html
Copyright © 2011-2022 走看看