Textarea值和文本属性在react中没有定义
textarea value and text attributes goes on undefined in react
我有一个textarea
<textarea ref="newText" defaultValue={this.props.children}></textarea>
我需要获取它的值,我试过了。
this.props.update(this.refs.newText.value,this.props.index);
我也用text代替value,但它仍然返回undefined
this.refs.newText.value
尝试更新你的react-dom库。Ref帮助您在不需要使用props的情况下强制修改子对象。从react docs获取最新版本
src="https://unpkg.com/react@15/dist/react.js">
src="https://unpkg.com/react-dom@15/dist/react-dom.js">
查看Refs &DOM
如果没有组件的完整源代码,很难进行调试。我准备了一个代码依赖,它显示了访问<textarea/>
元素中输入的值的两种方法:http://codepen.io/PiotrBerebecki/pen/amJAqb
也可以看看React Forms文档:https://facebook.github.io/react/docs/forms.html#controlled-components
const TextArea = React.createClass ({
getInitialState: function() {
return {
userInputValue: '',
userInputRefs: ''
};
},
handleChange: function(event) {
this.setState({
userInputValue: event.target.value
});
this.setState({
userInputRefs: this.refs.userData.value
});
},
render: function() {
return (
<div>
<textarea ref="userData"
type="text"
onChange={this.handleChange}
value={this.state.userInputValue} />
<h3>User input value:</h3>
<p>{this.state.userInputValue}</p>
<h3>User input refs:</h3>
<p>{this.state.userInputRefs}</p>
</div>
);
}
})
ReactDOM.render(
<TextArea />,
document.getElementById('app')
)
相关文章:
- React+Meteor:this.ops返回未定义
- React.createElement:类型不应为null或未定义
- React路由器错误-'无法调用方法'getRouteAtDepth'的未定义'
- React ReferenceError:未定义文档
- Gulp,浏览使用react作为CommonJS不起作用.React未定义
- React+Redux-未捕获错误:操作可能没有未定义的“;类型“;所有物
- 未捕获的ReferenceError:链接未定义React
- React返回未定义的JSON请求
- React JS无法读取属性'keys'的未定义
- 无法读取属性'道具'React容器中自定义onTouch函数中未定义的
- 如何从 React 中的事件对象访问自定义属性
- Webpack:定义'查询'带有react hot和babel的多个装载机
- 未捕获的ReferenceError:IndexRoute未定义-如何解决此错误以在react路由器中使用IndexRo
- 从 React 中的自定义元素中修改属性
- React Js注入(未定义React)
- 自定义React Native UI组件:不变量冲突
- 定义React应用中的所有HTML
- 无法读取property 'bind'的定义.React.js
- 下一步如何在自定义react redux中间件中定义
- 为什么会抛出这个异常?未捕获的ReferenceError:未定义React