如何在Reaction中訪問DOM元素?Reaction中document.getElementById()的等價鍵是什么?如何在react.js中選擇某些條?這是我的密碼:var Progressbar = React.createClass({
getInitialState: function () {
return { completed: this.props.completed };
},
addPrecent: function (value) {
this.props.completed += value;
this.setState({ completed: this.props.completed });
},
render: function () {
var completed = this.props.completed;
if (completed < 0) { completed = 0 };
return (...);
}我想使用這個Reaction組件:var App = React.createClass({
getInitialState: function () {
return { baction: 'Progress1' };
},
handleChange: function (e) {
var value = e.target.value;
console.log(value);
this.setState({ baction: value });
},
handleClick10: function (e) {
console.log('You clicked: ', this.state.baction);
document.getElementById(this.state.baction).addPrecent(10);
},我希望執(zhí)行handleClick 10函數(shù),并對所選的進(jìn)度條執(zhí)行操作。但我得到的結(jié)果是: You clicked: Progress1
TypeError: document.getElementById(...) is null如何選擇react.js中的特定元素?
如何在Reaction中訪問DOM元素?Reaction中document.getElement
眼眸繁星
2019-07-02 17:10:05