美文网首页
00001.HostListener 失去焦点时变换设定值

00001.HostListener 失去焦点时变换设定值

作者: 笑着字太黑 | 来源:发表于2023-05-16 09:09 被阅读0次
@HostListener('focusout', ['$event'])
    onBlur(event: FocusEvent): void {
      const tagName = (event.target as HTMLElement).tagName;
      const formControlTags = ['INPUT'];
      if (!formControlTags.includes(tagName)) {
        return;
      }

      const targetElement = event.target as HTMLInputElement;
      const pattern = targetElement.getAttribute("pattern");
      // 全角
      const awagpattern = "[^\\x20-\\x7E\\uFF61-\\uFF9F]{2,10}";
      if (pattern == awagpattern) {
        targetElement.value = "调用半角转换全角函数";
        targetElement.dispatchEvent(new Event('input'));
      }
    }

相关文章

网友评论

      本文标题:00001.HostListener 失去焦点时变换设定值

      本文链接:https://www.haomeiwen.com/subject/msnvsdtx.html