How to populate React-generated input fields with JQuery

前端 未结 2 501
离开以前
离开以前 2021-01-27 03:23

I\'m trying to write a bookmarklet to autofill a form, to simplify manual testing. The site is implemented in React. I\'ve tried using JQuery, for example:

$(\"#         


        
相关标签:
2条回答
  • 2021-01-27 03:44

    From our discussion in the comments, my guess is that you'll want to fire a change event for each input you plan on modifying.

    var element = document.getElementById('emailAddress'),
        event = {
            target: {
                value: 'new value for the input'
            }
        };
    element.onchange(event);
    
    0 讨论(0)
  • 2021-01-27 03:50
    //find element
    let elem = document.querySelector("#emailAddress");
    //create event
    let event = new Event('input', { bubbles: true });
    //set value
    elem.value="bob@example.com";
    //trigger event
    elem.dispatchEvent(event)
    
    0 讨论(0)
提交回复
热议问题