Javascript 将React prop传递到DOM元素时出现问题
我试图将输入限制为整数。我试图传递step属性,当直接在HTML中使用时,它似乎可以工作,但是我很难从react中传递它。下面是我的渲染方法,数字输入在底部。我遇到的问题是输入仍然接受十进制Javascript 将React prop传递到DOM元素时出现问题,javascript,html,reactjs,react-templates,Javascript,Html,Reactjs,React Templates,我试图将输入限制为整数。我试图传递step属性,当直接在HTML中使用时,它似乎可以工作,但是我很难从react中传递它。下面是我的渲染方法,数字输入在底部。我遇到的问题是输入仍然接受十进制 render() { const { currentVariableValue, type, currentVariable, variablePayload, } = this.props const lowHi = this.ge
render() {
const {
currentVariableValue,
type,
currentVariable,
variablePayload,
} = this.props
const lowHi = this.getLowHi()
const lowHiDisplay = `between ${lowHi[0]} and ${lowHi[1]}`
/* eslint-disable no-nested-ternary */
return (
<ResponseContainer>
{
type === 'text' ?
<TransparentTextArea
autoFocus
type="text"
value={ currentVariableValue }
onChange={ this.handleUpdateValue }
onFocus={ this.handleFocus }
onKeyPress={ this.handleKeyPress }
key={ currentVariable }
/> :
type === 'paragraph' ?
<TransparentTextArea
autoFocus
type="text"
value={ currentVariableValue }
onChange={ this.handleUpdateValue }
onFocus={ this.handleFocus }
onKeyPress={ this.handleKeyPress }
key={ currentVariable }
style={ { height: '300px', width: '95%', fontSize: '1.4em' } }
/> :
<TransparentInput
autoFocus
type="numeric"
value={ currentVariableValue }
onChange={ this.handleUpdateValue }
onFocus={ this.handleFocus }
onKeyPress={ this.handleKeyPress }
key={ currentVariable }
invalid={ !variablePayload.isValid }
step={ 1 }
/>
}
render(){
常数{
currentVariableValue,
类型,
当前变量,
可变有效载荷,
}=这是道具
const lowHi=this.getLowHi()
const lowHiDisplay=`介于${lowHi[0]}和${lowHi[1]}之间`
/*eslint禁用无嵌套三值*/
返回(
{
类型=='text'?
:
类型=='段落'?
:
}
在透明输入中,是否将{…props}传递给输入元素?在透明输入中,是否将{…props}传递给输入元素?错误在类型中。
将其更改为number
。例如:
<TransparentInput
autoFocus
type="number"
错误在您的类型中。
将其更改为number
。例如:
<TransparentInput
autoFocus
type="number"
>从react传递的问题是字段is仍然接受十进制值。>从react传递的问题是字段is仍然接受十进制值。