[英]React component event fire manually from client side browser console
In my website I have created a div element using React Js and its editable also. 在我的网站中,我使用React Js及其可编辑的元素创建了一个div元素。 If user edit the content it will trigger onInput function. 如果用户编辑内容,它将触发onInput函数。
r.createElement("div", {
dangerouslySetInnerHTML: {
__html: e
},
dir: "auto",
ref: "input",
spellCheck: this.props.spellCheck,
"data-tab": this.props.editable ? 1 : null ,
contentEditable: this.props.editable,
className: t,
onInput: this.onInput,
onPaste: this.onPaste,
onCut: this.onCut,
onKeyUp: this.onKeyUp,
onKeyPress: this.onKeyPress,
onMouseDown: this.onMouseDown,
onContextMenu: this.onContextMenu,
onFocus: this.props.onFocus,
onBlur: this.props.onBlur
}
I am trying to set content to that element from client chrome browser console and its not triggering the onInput event. 我正在尝试从客户端Chrome浏览器控制台将内容设置为该元素,并且其不会触发onInput事件。
My question is there a way to add input dynamically and call onInput event which is attached for the element. 我的问题是有一种方法可以动态添加输入并调用为元素附加的onInput事件 。
you can dispatch event from console 您可以从控制台调度事件
1.find dom node through querySelector.. , or select element in "Elements" tab and use $0; 1.通过querySelector ..找到dom节点,或在“ Elements”选项卡中选择元素并使用$ 0;
const input = document.querySelector('[contentEditable]');
2.create event 2.创建事件
const eventX = new Event('input', {bubbles: true});
3.change value 3.改变价值
input.textContent = "TEST";
4.dispatch event 4.派遣事件
input.dispatchEvent(eventX)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.