反应 - 如何转换A< div>输入
我有一个表,每行都有一些td
此处的2 td
对我很重要,我想更改它们:name
&amp ; family
。 我想更改每个名称
或family
td
当用户单击时。 我该如何处理此活动?
这是我的表td
:
finalList.map((i, index) => {
return (
<tr className="contactItem" id={i.id} key={i.id}>
<td>{String(index + 1).padStart(2, "0")}).</td>
<td id="editName" onClick={(e) => inlineEditHandler(e, i.name)}>{i.name}</td>
<td id="editFamily" onClick={(e) => inlineEditHandler(e, i.family)}>{i.family}</td>
<td>
{String(i.numbers[0]).substring(7, 11) +
"***" +
String(i.numbers[0]).substring(0, 4)}
</td>
<td className="itemBTNS">
<button
className="deleteBTN"
onClick={() => contactDeleteHandler(i.id)}
>
X
</button>
<button
className="editBTN"
onClick={() => contactEditHandler(i)}
>
Edit
</button>
</td>
</tr>
);
})
我想为第二和第三td
设置此事件。 并请注意,我不想使用contendeedible
属性。
inlineEditHandler = (e, i) => {
this.setState({
[e.target.id]: i,
});
};
editname
和editfamily
是我的状态。 我应该在InlineDithandler
函数或其他内容中做什么,以将tagName从td
更改为输入或类似的内容?
I have a table that each row that has some td
that here these 2 td
are important for me and I want to change them: name
& family
.
I want to change each name
or family
td
when the user clicks on it.
how can I handle this event?
this is my table td
:
finalList.map((i, index) => {
return (
<tr className="contactItem" id={i.id} key={i.id}>
<td>{String(index + 1).padStart(2, "0")}).</td>
<td id="editName" onClick={(e) => inlineEditHandler(e, i.name)}>{i.name}</td>
<td id="editFamily" onClick={(e) => inlineEditHandler(e, i.family)}>{i.family}</td>
<td>
{String(i.numbers[0]).substring(7, 11) +
"***" +
String(i.numbers[0]).substring(0, 4)}
</td>
<td className="itemBTNS">
<button
className="deleteBTN"
onClick={() => contactDeleteHandler(i.id)}
>
X
</button>
<button
className="editBTN"
onClick={() => contactEditHandler(i)}
>
Edit
</button>
</td>
</tr>
);
})
I want to set this event for the second and third td
.
And note that I don't want to use the contentEditable
attribute.
inlineEditHandler = (e, i) => {
this.setState({
[e.target.id]: i,
});
};
editName
and editFamily
are my states.
What should I do in the inlineEditHandler
function or other stuff to change the tagName from td
to input or something like this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论