简体   繁体   English

从客户端浏览器控制台手动响应组件事件触发

[英]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)

jsfiddle DEMO test jsfiddle演示测试

在此处输入图片说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 手动触发一个字段的客户端验证 - Manually fire client side validation for one field 浏览器控制台错误不影响客户端行为 - Browser Console Errors not affecting client side behaviour Dash React 下拉组件:无法从浏览器控制台打开 - Dash React Dropdown Component: Cannot open from Browser Console 在asp.net 中客户端脚本验证后触发事件? - Fire event after client side script validation in asp.net? 在客户端 JavaScript 中,是否可以捕获事件并在稍后阶段触发它? - In client-side JavaScript, is it possible to capture an event and fire it at a later stage? 当客户端使用Java脚本时,文本框将触发autopostback事件 - autopostback event will fire for textbox when java script desable at client side 从Chrome控制台手动触发事件监听器 - Manually trigger event listener from Chrome console 如何在项目Asp.net MVC4的服务器端手动触发回发事件以激活selectedIndexChanged事件 - How to manually fire postback event to activate selectedIndexChanged event on the server side of a project Asp.net mvc4 手动更换火灾事件 - Fire change-event manually 手动进行Perl和Selenium火灾事件 - Perl & Selenium fire event manually
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM