Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/456.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript ReactJs:fontSize从字体更改方法调用时不会更改_Javascript_Reactjs - Fatal编程技术网

Javascript ReactJs:fontSize从字体更改方法调用时不会更改

Javascript ReactJs:fontSize从字体更改方法调用时不会更改,javascript,reactjs,Javascript,Reactjs,我写了一个非常简单的代码。我将fontSize设置为我的状态。我想在更改输入值时更改fontSize。但它不起作用。有人能帮忙吗?提前谢谢 以下是我的js代码: import React from 'react'; import ReactDOM from 'react-dom'; import './index.css'; class Test extends React.Component{ constructor(props){ super(pr

我写了一个非常简单的代码。我将fontSize设置为我的状态。我想在更改输入值时更改fontSize。但它不起作用。有人能帮忙吗?提前谢谢

以下是我的js代码:

import React from 'react';
import ReactDOM from 'react-dom';
import './index.css';

    class Test extends React.Component{
       constructor(props){
          super(props)
          this.state={
              fontSize:64
          }
       }
       changeSize(event){
        this.setState({
            fontSize:event.target.value
        });
      }

      render(){
          let styleobj = {background:"blue",fontSize:64}
          return(
              <section style={styleobj}>
              <h2 className="tryout" style={{fontSize:this.state.fontSize}}>{this.state.fontSize}</h2>
              <input value={this.state.fontSize} onChange={this.changeSize.bind(this)}/>
              </section>
          );

      }
    }


    ReactDOM.render(<Test name="Sumei" value="123"/>,document.getElementById("root"));
从“React”导入React;
从“react dom”导入react dom;
导入“./index.css”;
类测试扩展了React.Component{
建造师(道具){
超级(道具)
这个州={
字体大小:64
}
}
更改大小(事件){
这是我的国家({
fontSize:event.target.value
});
}
render(){
让styleobj={background:“blue”,fontSize:64}
返回(
{this.state.fontSize}
);
}
}
render(,document.getElementById(“根”));

您需要指定字体大小的值
(em、px、rem、%…)

render(){
让styleobj={background:“blue”,fontSize:64}
返回(
{this.state.fontSize}
);
}
}

您需要指定fontSize的值(em、px、rem、%…)是否遇到错误?对于像素,唯一的数字就足够了。
  render() {
    let styleobj = { background: "blue", fontSize: 64 }
    return (
      <section style={styleobj}>
        <h2 className="tryout" style={{fontSize: this.state.fontSize+'px'}}>{this.state.fontSize}</h2>
        <input value={this.state.fontSize} onChange={this.changeSize.bind(this)} />
      </section>
    );

  }
}