Select 反应输入
Select React Input
假设我有以下代码:
function something() {
return (
<Input.Password name="password" id="password_id"/>
)
};
我想在 return 语句之外的 <Input.Password/>
上调用 .blur()
。有什么方法可以在函数中实现吗?
P.S。这是Ant Design输入的一部分。这是 API of the .blur()
function and the focus demo。我基本上想通过调用模糊函数来移除输入的焦点,但我不知道如何定位特定的输入字段。
提前致谢。
实际上你必须使用 ref 并赋值给输入
您可以在名称为 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"/>
)
};
我在您链接的文档中找到了这个:
<Space direction="vertical">
<Input.Password placeholder="input password" />
<Input.Password
placeholder="input password"
iconRender={visible => (visible ? <EyeTwoTone /> : <EyeInvisibleOutlined />)}
/>
这是一个带有眼睛图标的密码输入,点击后会显示该值。但是我对模糊方法一无所知
假设我有以下代码:
function something() {
return (
<Input.Password name="password" id="password_id"/>
)
};
我想在 return 语句之外的 <Input.Password/>
上调用 .blur()
。有什么方法可以在函数中实现吗?
P.S。这是Ant Design输入的一部分。这是 API of the .blur()
function and the focus demo。我基本上想通过调用模糊函数来移除输入的焦点,但我不知道如何定位特定的输入字段。
提前致谢。
实际上你必须使用 ref 并赋值给输入 您可以在名称为 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"/>
)
};
我在您链接的文档中找到了这个:
<Space direction="vertical">
<Input.Password placeholder="input password" />
<Input.Password
placeholder="input password"
iconRender={visible => (visible ? <EyeTwoTone /> : <EyeInvisibleOutlined />)}
/>
这是一个带有眼睛图标的密码输入,点击后会显示该值。但是我对模糊方法一无所知