第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機(jī)立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

如何在Reaction中訪問DOM元素?Reaction中document.getElement

如何在Reaction中訪問DOM元素?Reaction中document.getElement

眼眸繁星 2019-07-02 17:10:05
如何在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中的特定元素?
查看完整描述

3 回答

?
Cats萌萌

TA貢獻(xiàn)1805條經(jīng)驗 獲得超9個贊

你可以代替

document.getElementById(this.state.baction).addPrecent(10);

通過

this.refs[this.state.baction].addPrecent(10);


  <Progressbar completed={25} ref="Progress1" id="Progress1"/>


查看完整回答
反對 回復(fù) 2019-07-02
  • 3 回答
  • 0 關(guān)注
  • 849 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號