我试图模拟.click() event一个上作出反应元素,但我想不出为什么它不工作(当我烧了它不反应event).
我想仅使用JavaScript发布Facebook评论,但我坚持第一步(做一个.click()on div[class="UFIInputContainer"]元素).
我的代码是:
document.querySelector('div[class="UFIInputContainer"]').click();
Run Code Online (Sandbox Code Playgroud)
这是我尝试这样做的URL:https://www.facebook.com/plugins/feedback.php ...
PS我对React没有经验,我不知道这在技术上是否可行.这是可能的?
编辑:我正试图这样做Chrome DevTools Console.
这是我在渲染方法中的表单,用于用户登录。
<form onSubmit={this.handleSubmit}>
  <Avatar className={classes.avatar}>
    <LockOutlinedIcon />
  </Avatar>
  <Typography component="h1" variant="h5">
    Sign in
  </Typography>
  <TextField variant="outlined" margin="normal" fullWidth id="email"
    label="Email Address" name="email" onChange={this.handleEmailChange}
  />
  <TextField variant="outlined" margin="normal" fullWidth
    name="password" onChange={this.handlePasswordChange}
  />
  {loginError && (
    <Typography component="p" className={classes.errorText}>
      Incorrect email or password.
    </Typography>
  )}
  <Button type="button" fullWidth variant="contained" color="primary"
    className={classes.submit} onClick={this.handleSubmit}
  >
    Sign In
  </Button>
</form>
Run Code Online (Sandbox Code Playgroud)
以下是我的句柄提交方法。
handleSubmit = () => {
  const { dispatch } = this.props;
  const { email, password } = this.state;
  dispatch(loginUser(email, password));
};
Run Code Online (Sandbox Code Playgroud)
如何通过按键提交表单Enter?我正在使用标准的 …
我正在创建一个 React 应用程序,其中有一种称为输入的状态,它正在从用户那里获取输入。我希望当我按下回车键时,警报应该显示正在设置状态的输入。但是,单击enter按键时,仅显示输入状态中设置的默认值。
但是,当我单击按钮(我创建该按钮是为了在警报中显示输入)时,警报中显示的输入是正确的。
请参阅下面的代码片段以供参考:
import React, { useEffect, useRef, useState } from 'react';
export default function ShowAlertExample() {
  const [input, setInput ] = useState('1');
  const handleInputChange = (e) => {
    setInput(e.target.value);
  }
  const handleShowAlert = () => {
    alert(input);
  }
  const checkKeyPress = (e) =>{
    const { key, keyCode } = e;
    console.log(key, keyCode)
    if (keyCode === 13 ) {
      alert(input);
    }
  }
  useEffect(()=>{
    window.addEventListener("keydown", checkKeyPress)
    return ()=>{
      window.removeEventListener("keydown", checkKeyPress)
    }
  }, [])
  
  return (
    <div>
      <header …Run Code Online (Sandbox Code Playgroud)