记录一下 React input输入框不生效的问题

zetalpha 2023/10/6 发布 · 2023/10/6 更新 · 1340 次阅读

选一个能用就行


let input = document.getElementById(‘userName’)
let lastValue = input.value
input.value=‘123’
let event = new Event(‘input’, { bubbles: true })
let tracker = input._valueTracker
if(tracker) {
tracker.setValue(lastValue)
}
input.dispatchEvent(event)

let input = document.querySelector(’input‘);
 let lastValue = input.value;
 input.value = ’test‘;
 let event = new Event('input', { bubbles: true });
 event.simulated = true;
  et tracker = input._valueTracker;
 if (tracker) {
    tracker.setValue(lastValue);
 }
 input.dispatchEvent(event);
 
· {{comment.createTimeStr}}
{{reply.votePoints}}
回复   – {{reply.createTimeStr}}
回复 x
标签
目录
相关操作