【发布时间】:2021-03-23 21:31:49
【问题描述】:
我需要添加一个值(从下拉列表中),这将添加到输入字段中的“光标位置”:
import { useState } from "react";
import "./styles.css";
export default function App() {
const [cur, setCur] = useState("");
const [state, setState] = useState("");
const [dropVal, setDropVal] = useState("");
const handleChange = (e) => {
setState(e.target.value);
// gives cursor index
// this only shows cursor position if user types
// I need to track the position of the cursor and add dropVal there
setCur(e.target.selectionStart);
};
return (
<div className="App">
<input onChange={(e) => handleChange(e)} value={state} />
<select onChange={(e) => setDropVal(e.target.value)} >
<option>ONE</option>
<option>TWO</option>
</select>
</div>
);
}
我试过这个,这是不完整的,找不到在任何地方实现它的方法。 感谢您的帮助,在此先感谢!
【问题讨论】:
标签: javascript reactjs react-native react-redux