网站无法识别我使用 Javascript 进行的输入更改

问题描述 投票:0回答:1

我想做一个 CSGOROLL Bot 来学习一点 Javascript。每次我更改投注值时,网站只会采用我之前手动输入的值。

我试图改变价值

document.getElementsByClassName("mat-input-element mat-form-field-autofill-control cdk-text-field-autofill-monitored ng-touched ng-dirty ng-invalid")[0].value = 0.05;

我用 querySelector 试了一下。它更改了输入字段中的值,但是当我按红色或黑色时,值不是我更改的值。Here is an Example of the Problem

javascript input getelementsbyclassname queryselector gambling
1个回答
0
投票

当您直接使用 JavaScript 更改输入字段的值时,Angular 不会自动检测更改并更新其内部状态。因此,当您提交表单或按下按钮时,旧值仍在使用。

要更新 Angular 内部状态中的值,您需要触发 Angular 监听的事件,例如

input
事件。以下是使用代码执行此操作的方法:

// Get the input element
const inputElement = document.getElementsByClassName("mat-input-element mat-form-field-autofill-control cdk-text-field-autofill-monitored ng-touched ng-dirty ng-invalid")[0];

// Set the new value
inputElement.value = 0.05;

// Trigger the 'input' event to update Angular's internal state
const event = new Event('input', { bubbles: true });
inputElement.dispatchEvent(event);

此代码将更新输入字段中的值并触发

input
事件,以便 Angular 更新其内部状态。现在当你按下红色或黑色时,应该使用新值。

© www.soinside.com 2019 - 2024. All rights reserved.