How to get selected value of a dropdown menu in ReactJS

后端 未结 9 1949
迷失自我
迷失自我 2020-12-04 10:03

I\'m using react and I want to get the value of the selected option of a dropdown in react but I don\'t know how. Any suggestions? thanks! My dropdown is just a select like:

9条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-12-04 10:39

    As for front-end developer many time we are dealing with the forms in which we have to handle the dropdowns and we have to use the value of selected dropdown to perform some action or the send the value on the Server, it's very simple you have to write the simple dropdown in HTML just put the one onChange method for the selection in the dropdown whenever user change the value of dropdown set that value to state so you can easily access it in AvFeaturedPlayList 1 remember you will always get the result as option value and not the dropdown text which is displayed on the screen

    import React, { Component } from "react";
    import { Server } from "net";
    
    class InlineStyle extends Component {
      constructor(props) {
        super(props);
        this.state = {
          selectValue: ""
        };
    
        this.handleDropdownChange = this.handleDropdownChange.bind(this);
      }
    
      handleDropdownChange(e) {
        this.setState({ selectValue: e.target.value });
      }
    
      render() {
        return (
          
    Selected value is : {this.state.selectValue}
    ); } } export default InlineStyle;

提交回复
热议问题