小编meh*_*ibi的帖子

如何设置单选按钮默认选中反应?

我用 3 个单选按钮创建了单选按钮:我想将石灰作为默认选中的单选按钮,我将石灰设置为默认值,但它不起作用。

这是我的代码我不知道如何解决我的问题。

    import React, {Component} from 'react';

    class App extends Component{
      constructor(props){
        super(props)

        this.handleflavorSubmit = this.handleflavorSubmit.bind(this)
        this.onChangeRadio = this.onChangeRadio.bind(this)


        this.state = {value : 'lime'};
        }

      onChangeRadio(e){
        this.setState({value : e.target.value})
      }

      handleflavorSubmit(e){
        alert("your favorite flavor is " + this.state.value)
        e.preventDefault();
      }

      render(){

        return( 
          <div>
            <h1>Choose your flavor:</h1>
            <form onSubmit = {this.handleflavorSubmit}>
              <input type="radio" checked = {this.state.value === 'grapefruit'} onChange = {this.onChangeRadio} value= "grapefruit"/>Grapefruit
              <input type = "radio" checked = {this.state.value === 'lime'} onChange = {this.onChangeRadio} value = "lime"/>Lime
              <input …
Run Code Online (Sandbox Code Playgroud)

html javascript jsx reactjs

5
推荐指数
1
解决办法
7986
查看次数

如何在反应中实施和解概念?

我想在列表中添加一个字符串,并且有一个CounterComponent与分开工作的字符串,我HelloWordComponent为Microsoft设置1,为FaceBook设置2,为React设置3;当我将“ yahoo”添加到列表的第一行时,“ yahoo”的计数器设置为1,并且反应变为0。

我知道我必须使用唯一的密钥,并且我认为它{name}是合格的,但是我不知道key = {name}确切地在哪里使用?

class HelloWordComponent extends React.Component {
  render() {
    return <div>{this.props.name}</div>
  }
}

class Counter extends React.Component {
    constructor(){
        super()

        this.onPlusClick = this.onPlusClick.bind(this)

         this.state = {count : 0}
    }

    onPlusClick(){
        this.setState(prevState => ({count: prevState.count + 1}))
    }

    render(){
        return <div>
            {this.state.count}
            <button onClick = {this.onPlusClick}>+</button>
        </div>
    }
}

class App extends React.Component{
  constructor(){
    super()

    this.addName = this.addName.bind(this)

    this.state = {
      name: "Sara",
      list:['Microsoft', 'FaceBook', 'React']
    }

  }

  addName(){ …
Run Code Online (Sandbox Code Playgroud)

reactjs

4
推荐指数
1
解决办法
49
查看次数

如何解决使用字符串、格式时运行时错误的问题

我必须按特定格式将此字符串映射到我的属性中dataModel,因此我用来string.Format()处理它,但我遇到了一个运行时错误

输入字符串的格式不正确!

怎么才能以正确的格式写出来呢?

Value = string.Format("guid{({0})}title{({1})}parameterName{({2})}", retirementItem.Guid, retirementItem.Title, retirementItem.ParameterName)
Run Code Online (Sandbox Code Playgroud)

c# asp.net

1
推荐指数
1
解决办法
105
查看次数

标签 统计

reactjs ×2

asp.net ×1

c# ×1

html ×1

javascript ×1

jsx ×1