React.js setting value of input

后端 未结 7 1427
既然无缘
既然无缘 2020-12-14 07:51

I am a beginner with react.js and it\'s amazing but I am facing a real problem: I need to set the value of an input using plain and pure javascript but form some reason reac

7条回答
  •  孤街浪徒
    2020-12-14 08:42

    I have written and use this function to trigger the change state for the field:

    function doEvent( obj, event ) {
        /* Created by David@Refoua.me */
        var event = new Event( event, {target: obj, bubbles: true} );
        return obj ? obj.dispatchEvent(event) : false;
    }
    

    Use it like this:

    var el = document.getElementById("CntctFrm2emailField");
    el.value = "testing@gmail.com";
    doEvent( el, 'input' );
    

提交回复
热议问题