gpt4 book ai didi

javascript - 访问 td 元素中的所有输入/文本框

转载 作者:行者123 更新时间:2023-12-02 17:14:26 24 4
gpt4 key购买 nike

我使用的表格具有最后一列中带有“编辑”字样的超链接。前两列中有两个文本框,其 readonly 值设置为 true。

当用户单击“编辑”链接时,我想将 readonly 属性更改为 false,并将超链接的措辞更改为“保存”。

click函数附加到超链接后,如何访问这两个文本框?我的第一个想法是检查 .parent 元素中的 input 并从那里开始,但这不起作用。我还尝试寻找 closest td 元素并在任何 input 上执行 .find 但我不能让它工作(尽管我可能错误地循环输入输入

这是我到目前为止所拥有的:

    $('.editException').click(function () {
if ($(this).text() == 'Save') {

} else {
//Change text of hyperlink (this is working)
$(this).text('Save');

//My two attempts at making the text boxes non-readonly
$(this).parent('input').attr('readonly', false);
$(this).closest('td').find('input').each(function () {
this.readOnly = false;
});
});

最佳答案

试试这个:

$(this).closest('tr').find('input').attr('readonly', false);

您需要一直到达 TR,因为输入位于不同的列中。您不需要 .each(),因为 .attr() 适用于所有选定的元素。

关于javascript - 访问 td 元素中的所有输入/文本框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24560979/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com