[英]Input Box problem In reactjs, On single click cursor is not pointing in text-box , On double click in the text-box Input Cursor is coming
我對此很陌生。 下面是代碼,請幫助
單擊時,輸入光標未指向文本框中,雙擊時,輸入光標即將出現。 另外,如果我要添加占位符,則無法輸入任何內容。
export default class Login extends Component {
state = {
UserID: "",
Password: ""
};
UserIdchangeHandler = text => {
this.setState({
UserID: text.target.value
});
};
PasswordchangeHandler = text => {
this.setState({
Password: text.target.value
});
};
render() {
return (
<div className="backgroundImg">
<span>
<FontAwesomeIcon icon={faUserTie} size="lg" />
</span>
<input
type="text"
onChange={text => {
this.UserIdchangeHandler(text);
}}
/>
<br />
<span>
<FontAwesomeIcon icon={faKey} size="lg" />
</span>
<input
type="password"
onChange={text => {
this.UserIdchangeHandler(text);
}}
/>
<br />
<button>Login</button>
</div>
);
}
}
import React, {Component} from 'react';
import "./login.css";
import { library, text } from '@fortawesome/fontawesome-svg-core'
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'
import { faUserTie, faKey, } from '@fortawesome/free-solid-svg-icons'
library.add(faUserTie)
export default class Login extends Component{
state={
UserID:"",
Password:""
}
UserIdchangeHandler=(text)=>{
this.setState({
UserID:text.target.value
})
}
PasswordchangeHandler=(pass)=>{
this.setState({
Password:pass.target.value
})
}
render() {
return (
<div className="backgroundImg">
<span>
<FontAwesomeIcon icon={faUserTie} size="lg"></FontAwesomeIcon>
</span>
<input type="text" onChange={(text)=>{this.UserIdchangeHandler(text)}} ></input>
<br/>
<span>
<FontAwesomeIcon icon={faKey} size="lg"></FontAwesomeIcon>
</span>
<input type="password" onChange={(pass)=>{this.PasswordchangeHandler(pass)}}></input>
<br/>
<button>Login</button>
</div>
);
}
}
發生的情況是您具有onChange處理程序,但未在輸入中設置值。
如果添加onChange處理程序,則需要添加值prop
<input
type="text"
value={this.stateUserId} // You're missing this here
onChange={evt => {
this.UserIdchangeHandler(evt);
}}
/>
您可以在此處了解有關React Docs的更多信息。 在您的情況下,您嘗試創建受控輸入 https://reactjs.org/docs/forms.html# 受控組件
旁注:在onChange中,您標記了屬性text
。 但最好將其稱為event
<input
type="text"
value={this.state.UserID} // you are missing value here.
onChange={text => {
this.UserIdchangeHandler(text);
}
}
/>
與密碼輸入字段相同。
問題現在解決了。 問題出在班級的CSS上。 Z索引設置為較低的值。增加Z索引對我有幫助。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.