一只斗牛犬
2022-01-13 11:04:07
有一個(gè)html頁(yè)面包含以下html并包含一個(gè)js文件html:<input type="text" name="customValue" id="customValue" value="">.js 文件: class Calc extends React.Component { constructor() { super(); } render() { return (99) } } ReactDOM.render(<Calc />, document.getElementById("customValue"));所以我的問(wèn)題是如何使用 reactjs 將 customValue 設(shè)置為 99?
1 回答

紫衣仙女
TA貢獻(xiàn)1839條經(jīng)驗(yàn) 獲得超15個(gè)贊
你可以這樣做: -
HTML
<div id="rootDiv"></div>
JS
class Calc extends React.Component {
constructor() {
super();
}
getValue = () => {
return 99;
}
render() {
const value = this.getValue();
return (
<input type="text" name="customValue" id="customValue" value={value}>
)
}
}
ReactDOM.render(<Calc />, document.getElementById("rootDiv"));
添加回答
舉報(bào)
0/150
提交
取消