【问题标题】:Select React Input选择反应输入
【发布时间】:2021-06-04 12:54:07
【问题描述】:

假设我有以下代码:

function something() {
  return (
    <Input.Password name="password" id="password_id"/>
  )
};

我想在 return 语句之外在 &lt;Input.Password/&gt; 上调用 .blur()。有什么方法可以在函数中实现这一点吗?

附:这是 Ant Design 输入的一部分。这是.blur() 函数的APIfocus demo。我本质上是想通过调用 blur 函数来消除输入的焦点,但我不知道如何定位特定的输入字段。

提前致谢。

【问题讨论】:

  • 使用布尔值的最佳方式

标签: reactjs antd


【解决方案1】:

实际上你必须使用 ref 和 assignt 来输入 您可以使用任何名称为 var.current

    import React, {useRef,useEffect} from "react"
    
    
     function something() {
        const ref = useRef(null)
        
        
        useEffect(() => {
          consle.log(ref.current)
          ref.current.focus();
         
    
    , []}
    
    
       
          return (
            <Input.Password ref={ref} name="password" id="password_id"/>
          )
        };

【讨论】:

    【解决方案2】:

    我在您链接的文档中找到了这个:

    <Space direction="vertical">
      <Input.Password placeholder="input password" />
      <Input.Password
       placeholder="input password"
       iconRender={visible => (visible ? <EyeTwoTone /> : <EyeInvisibleOutlined />)}
    />
    

    这是一个带有眼睛图标的密码输入,可在点击时显示值。但是我没有发现模糊方法

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-08-01
      • 1970-01-01
      • 2020-06-27
      • 1970-01-01
      • 1970-01-01
      • 2020-07-04
      • 2017-11-24
      相关资源
      最近更新 更多