我有一张这样的桌子:
Column 1 | Column 2
-------------------
Textbox1 | Text1
Textbox2 | Text2
我想更改Textbox1
值,当光标移出时,它将运行change
事件以将Text1
值替换为Success
.
<html>
<head>
<title>Demo - Change Value</title>
<script type="text/javascript" language="javascript" src="js/jquery.js"></script>
<script>
$(document).ready(function() {
$('#example table tbody tr td input').change(function() {
var rowEdit = $($(this).parents('tr').html());
rowEdit.closest('.sub').html('Success');
<!-- $('.sub').html('Change');-->
})
})
</script>
</head>
<body>
<div id="example">
<table>
<thead>
<th>Column 1</th>
<th>Column 2</th>
</thead>
<tbody>
<tr>
<td><input type="text" /></td>
<td class="sub">123</td>
</tr>
<tr>
<td><input type="text" /></td>
<td class="sub">456</td>
</tr>
</tbody>
</table>
</div>
</body>
</html>
问题是,在我调用之后值没有改变,但rowEdit.closest('.sub').html('success');
如果我使用.Text1
Text2
$('.sub').html('Change');
input
我的目标是在更改具有同一行的第 1 列的值时更改第 2 列内的文本。我怎样才能做到这一点?