【发布时间】:2021-06-23 03:55:00
【问题描述】:
我正在尝试在单击相应的刻度按钮时添加线条罢工或更改列表元素的背景颜色请建议一种方法来这样做..
有没有类似于jquery的前任的方法-$("p").css("background-color");
&对于初学者更适合掌握谁来自jq后台Class组件还是Functional
const [input, setValue] = useState("");
const [todos, setTodos] = useState([]);
// passing entered
const handleInput = (event) => {
setValue(event.target.value);
};
const lp = (event) => {
// let c = [1,2,34,55]
event.preventDefault();
// if no input nothing will happen return none
if (!input) return;
// using spread operator its used whenever we need to add array data to exiting array
const newTodos = [...todos, input];
setTodos(newTodos);
// clearing input text
setValue("");
};
const handeldel=(index) => {
// console.log(index)
todos.splice(index, 1);
setTodos([...todos]);
// const newTodos = todos.splice(index, 1);
// setTodos([...newTodos]);
}
const markdone =() => {
// how to mark complete
}
return (
<div>
<h1 className="text-center font-weight-bolder alert-info mb-5">Tasks To Do <i class="fas fa-clipboard-list text-success"></i></h1>
<div class="input-group mb-3 container">
<input
className="form-control border-primary font-weight-bold"
style={{ height: 60 }}
placeholder="Enter Text here"
type="text"
value={input}
onChange={handleInput}
/>
<div class="input-group-append">
<button
className="input-group-append font-weight-bolder "
style={{ fontSize: 20 }}
onClick={lp}
>
{" "}
<i class="fas fa-plus-square fa-2x p-2"></i>{" "}
</button>
</div>
</div>
{todos.map((x,index) => (
<ol style={{ listStyle:"outside" }} className="container">
<li className="font-weight-bolder table-bordered text-capitalize alert-secondary " style={{fontSize:30}}>
{ x }<i class="fas fa-check-circle float-md-right text-success" onClick={markdone}></i> <i class="fas fa-trash-alt text-danger float-md-right" onClick={()=>handeldel(index)}></i>
</li>
</ol>
))}
{/* for future ref */}
{/* <div >
{data.map((user) => (
<div className="user">{user.id + " " + user.name
}</div>
))}
</div> */}
</div>
);
【问题讨论】:
标签: javascript html css reactjs react-native