Skip to content

Instantly share code, notes, and snippets.

@sunzsh
Last active May 24, 2023 14:53
Show Gist options
  • Save sunzsh/874d2e5e214a660fd5b8f75fea0a5b5a to your computer and use it in GitHub Desktop.
Save sunzsh/874d2e5e214a660fd5b8f75fea0a5b5a to your computer and use it in GitHub Desktop.
react文本框赋值方法
javascript:(function(){setNativeValue=function(qs,value){const element=document.querySelector(qs);const valueSetter=Object.getOwnPropertyDescriptor(element,'value').set;const prototype=Object.getPrototypeOf(element);const prototypeValueSetter=Object.getOwnPropertyDescriptor(prototype,'value').set;if(valueSetter&&valueSetter!==prototypeValueSetter){prototypeValueSetter.call(element,value)}else{valueSetter.call(element,value)}element.dispatchEvent(new Event('input',{bubbles:true}))};})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment