sách gpt4 ai đã đi

reactjs - 自动选择输入中的文本 - Reactjs

In lại 作者:行者123 更新时间:2023-12-03 14:04:33 28 4
mua khóa gpt4 Nike

有没有办法在渲染后立即选择要覆盖的文本?我的意思是选择 - nhập mô tả hình ảnh ở đây

1 Câu trả lời

您可以尝试使用两种方法.focus.select

.focus() method sets focus on the specified element, if it can be focused.

.select() method selects all the text in a element or an element with a text field.

const App = React.createClass({
getInitialState() {
return { text: 'Default text' }
},

componentDidMount() {
this.refs.input.focus();
},

handleChange(e) {
this.setState({ text: e.target.value })
},

handleFocus(e) {
e.currentTarget.select();
},

handleClick() {
this.refs.input.focus();
},

render() {
return


type="text"
ref="input"
value={ this.state.text }
onChange={ this.handleChange }
onFocus={ this.handleFocus }
/>

{ this.state.text }



;
}
});


ReactDOM.render(
,
document.getElementById('container')
);


关于reactjs - 自动选择输入中的文本 - Reactjs,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39361859/

28 4 0
行者123
Hồ sơ cá nhân

Tôi là một lập trình viên xuất sắc, rất giỏi!

Nhận phiếu giảm giá Didi Taxi miễn phí
Mã giảm giá Didi Taxi
Giấy chứng nhận ICP Bắc Kinh số 000000
Hợp tác quảng cáo: 1813099741@qq.com 6ren.com