React.js setting value of input

后端 未结 7 1410
既然无缘
既然无缘 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:38

    I had a form that I needed to submit for some monitoring. I did it like this:

    $("input[type=email]").value = "me@something.com"
    $("input[type=email]").defaultValue = "me@something.com"
    $("input[type=password]").value = "mystellarpassword"
    $("input[type=password]").defaultValue = "pinpmystellarpasswordss"
    $("input[type=email]").dispatchEvent(new Event('input', {target: $("input[type=email]"), bubbles: true} ));
    $("input[type=password]").dispatchEvent(new Event('input', {target: $("input[type=password]"), bubbles: true} ));
    $("button.login").click()
    

    Note that for the website I was logging into, I had to set both value and defaultValue. There was some extra validation logic bound to the input.value

提交回复
热议问题