首页 > 解决方案 > 仅允许在材质 ui 中达到一定长度的数字

问题描述

我们需要用户只输入数字,它的最大长度应该是 3。我们如何在材料 ui 中完成这个?

<TextField
  id="score"
  label="score"
  className={classes.textField}
  name="totalScore"
  margin="normal"
  defaultValue={score}
/>

我们这里只需要数值

标签: javascripthtmlreactjsmaterial-ui

解决方案


尝试这个...

<TextField
  id="score"
  label="score"
  name="totalScore"
  style={style.filedStyle}
  inputProps={{ min: 3, max: 3}}
/>

推荐阅读