Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
169 views
in Technique[技术] by (71.8m points)

change images onclick in reactjs

const imagesPath = {
  eligibilitypng: "C:/Users/DHANUNJAY/datri/src/validatemoilenumberpng.png.",
  validatemoilenumberpng: "C:/Users/DHANUNJAY/datri/src/eligibilitypng.png"
}
         
class App extends Component {        
  state = {
    open: true
  }  
  toggleImage = () => {
    this.setState(state => ({ open: !state.open }))
  }

  getImageName = () => this.state.open ? 'eligibilitypng' : 'validatemoilenumberpng' 
  render() {    
    const imageName = this.getImageName();

    return (           
      <HashRouter>        
       <nav className="nav">         
        <div>      
        <div className="content">
        <div class="donorTitle"><b>Donor Registration</b></div>  <br/>    
          <ul className="header">  
          <div class="sibling-fade">

            <font size="18px" color="white"><li> <NavLink to="/"><img src={eligibilitypng} onClick={this.toggleImage}/></NavLink></li></font>
            <li> <NavLink to="/ValidateMobileNumber"><img src={validatemoilenumberpng}/> </NavLink></li> 
            
        </div>      
             <Route exact path="/" component={EligibilityCheck}/> 
            <Route path="/ValidateMobileNumber" component={ValidateMobileNumber}/>
            
            </div>      
        </nav>    
        </HashRouter>          
    );     
  }      
}          
const rootElement = document.getElementById("root");
ReactDOM.render(<App />, rootElement);
      
export default App;             
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
import eligibilitypng from "C:/Users/DHANUNJAY/datri/src/validatemoilenumberpng.png.";
import validatemoilenumberpng from "C:/Users/DHANUNJAY/datri/src/eligibilitypng.png";


<li onClick={this.toggleImage}>{this.state.open ? <img src={eligibilitypng} /> : <img src={validatemoilenumberpng } />}</li>

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...