在react js中主动触发onchange事件

React关于Input的基本语法--注意点

1、this.state:存储数据

2、用onChange监听事件;而不是onchange(JS里面的写法)

3、JSX用到了JS代码,需要用花括号{}包围

4、应用组件时,得用ES6的bind(this),绑到组件上去

5、要改变数据状态,不能直接用this.state.inputValue...;用this.setState(...);

6、写注释:{/*注释*/} 或{//(单独一行) } - - render里面的return部分就是JSX模块

 

查找资料 https://www.itranslater.com/qa/details/2326034152447017984

上面说 ,可以在事件对象上使用simulated标志,以使事件通过

var ev = new Event('input', { bubbles: true});
ev.simulated = true;
element.value = 'Something new';
element.dispatchEvent(ev);
加上后好使了

posted on 2022-03-14 13:25  天军  阅读(1055)  评论(0编辑  收藏  举报

导航