我正在使用一个表,该表的超链接在最后一栏中带有“编辑”字样。在前两列中是两个文本框,其readonly
值设置为true。
当用户单击“编辑”链接时,我想将readonly
属性更改为false,并将超链接的措辞更改为“保存”。
将click
功能附加到超链接后,如何访问两个文本框?我的第一个想法是检查.parent
元素input
并从那里去,但这没有用。我也尝试过查找closest
td
元素并对其进行.find
任何操作,input
但我也无法使它正常工作(尽管我可能会inputs
错误地遍历整个循环。
这是我到目前为止的内容:
$('.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()
适用于所有选定的元素。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句