美文网首页
react修改input值

react修改input值

作者: 卡地亚克思 | 来源:发表于2022-02-17 02:56 被阅读0次

```

function changeReactInputValue(inputDom,newText){

let lastValue = inputDom.value;

inputDom.value = newText;

let event = new Event('input', { bubbles: true });

event.simulated = true;

let tracker = inputDom._valueTracker;

if (tracker) {

  tracker.setValue(lastValue);

}

inputDom.dispatchEvent(event);

}

```

相关文章

网友评论

      本文标题:react修改input值

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