方法1:
$textarea = document.querySelector("textarea"); $textarea.value = item.content; let evt = new Event('input', { bubbles: true }); //evt.simulated = true; let tracker = $textarea._valueTracker; if(tracker){ tracker.setValue(""); } $textarea.dispatchEvent(evt);
方法2:
$textarea = document.querySelector("textarea"); $textarea.value = item.content; $textarea.dispatchEvent(new Event('input'));
按键事件:
$textarea = document.querySelector("textarea"); $textarea.focus(); let evt = new KeyboardEvent('keydown', {key: 'a11', code: '', location: 0, repeat: false, isComposing: false}); $textarea.dispatchEvent(evt);