javascript - 如何在 Angular JS (1.6) 驱动的网站中预填充数据时触发手动输入事件
问题描述
需要预填充数据并确保它通过验证。目前,当用户手动输入数据时会触发验证。
解决方案
我们可以使用以下代码实现结果。
const elem = document.getElementById('mat-input-0');
elem.value = 'smtomymail@gmail.com';
elem.dispatchEvent(new Event('input'));
elem.dispatchEvent(new Event('change'));
const elem1 = document.getElementById('mat-input-2');
elem1.value = 'Password123';
elem1.dispatchEvent(new Event('input'));
elem1.dispatchEvent(new Event('change'));
const elem2 = document.getElementById('mat-input-3');
elem2.value = 'Password123';
elem2.dispatchEvent(new Event('input'));
elem2.dispatchEvent(new Event('change'));
推荐阅读
- r - 结果的行数不是R中向量长度(arg 5)的倍数
- javascript - 从 OpenLayers 中的 GeoJSON 属性设置图标源
- angular - 以编程方式关闭所有打开的 cdk-overlay
- php - Symfony for PHP:使用 foreach 从会话向表中插入多行
- python-3.x - 推导表达式后如何通过 sympy 知道自动替换的值?
- c# - 从注入 DI 的 IHttpClientFactory 获取名称 HttpClient
- sql - 如何获取时间范围内的客户数量和总额?
- vba - 多个条件 IF 语句继续下一个用户表单
- sql - 错误:从 asp.net 中的存储过程获取值时,对象引用未设置为对象的实例
- java - 合并两个 PriorityQueue 的时间复杂度(Big-O)