亚洲中字慕日产2020,大陆极品少妇内射AAAAAA,无码av大香线蕉伊人久久,久久精品国产亚洲av麻豆网站

資訊專(zhuān)欄INFORMATION COLUMN

React 表單元素

894974231 / 3482人閱讀

摘要:今天來(lái)講講的表單元素。在中,并不使用之前的屬性,而在根標(biāo)簽上用屬性來(lái)表示選中項(xiàng)。多個(gè)輸入的解決方法當(dāng)你有處理多個(gè)受控的元素時(shí),你可以通過(guò)給每個(gè)元素添加一個(gè)屬性,來(lái)讓處理函數(shù)根據(jù)的值來(lái)選擇做什么。

今天來(lái)講講react的表單元素。
受控元素
下面來(lái)看一下如何獲取輸入框的值

import React, { Component } from "react";

class Trem extends React.Component {
    constructor(props){
        super(props);
        this.inp = this.inp.bind(this);
        this.sub = this.sub.bind(this);
        this.state = {
            place:"請(qǐng)輸入...",
            inputV:""
        }
    };
    inp(e){
        this.setState({
            inputV:e.target.value     {/* 通過(guò)事件細(xì)節(jié)改變inputV的值*/}
        });
        console.log(e.target.value)
    };    
    sub(){
      console.log(this.state.inputV)
    };    
    render(){
        return (
            

{/*此處的main是來(lái)自父組件的傳值*/}
) } } export default Trem;

代碼解讀:
this.inp = this.inp.bind(this); 綁定inp函數(shù)this指向
this.state 初始化變量
inp() 監(jiān)聽(tīng)input的輸入值
this.state.inputV 通過(guò)賦值獲取input的value

textarea 標(biāo)簽

import React, { Component } from "react";

class Trem extends React.Component {
    constructor(props){
        super(props);
        this.inp = this.inp.bind(this);
        this.sub = this.sub.bind(this);
        this.state = {
            place:"請(qǐng)輸入...",
            inputV:""
        }
    };
    inp(e){
        this.setState({
            inputV:e.target.value    
        });
        console.log(e.target.value)
    };    
    sub(){
      console.log(this.state.inputV)
    };    
    render(){
        return (