正确的$table.currentRow.1stCell语法
Correct syntax of $table.currentRow.1stCell
我的javascript:
$(document).on("keypress", "#desc", function(e) { //#desc to `$table.currentRow.1stCell`
$('#cd').val() = "was change";
});
这是我的HTML:
<table>
<tr>
<td>
<input type="text" id="cd">
</td>
<td>
<input type="text" id="desc">
</td>
</tr>//1st row
<tr>
<td>
<input type="text" id="cd">
</td>
<td>
<input type="text" id="desc">
</td>
</tr>//2nd row
</table>
如您所见,我使用id
,因此当我键入第一行或第二行时,第一行和第二行的第一个单元格都被更改。我想不使用id
或class
,但像$table.currentRow.1stCell
但不知道什么是正确的格式,所以我只能改变当前行。五月天,谢谢!谢谢:)
将第一个单元格的文本更改为输入
的基本思想$("tbody").on("change", "input", function() {
$(this) //input
.closest("tr") //finds the row associated with the input
.find("td:first") //returns the first cell
.text(this.value); //sets the text
});
http://jsfiddle.net/yvDDp/既然你改变了问题的HTML:
$("tbody").on("change", "tr td:nth-child(2) input", function () {
$(this) //input
.closest("tr") //finds the row associated with the input
.find("td:first input") //returns the first cell's input
.val(this.value); //sets the value
});
http://jsfiddle.net/yvDDp/1/您可以试一下这段代码是否正常
$(document).on("keypress","#desc",function(e){ //#desc to `$table.currentRow.1stCell`
//tr parent element find first input;
$(this).parent().parent().find("input").first().val('was change');
});
});