我有这样的一个表:变化元素值
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');
。
我的目标是更改列2中的文本,当我更改第1列的值input
与同一行。我怎样才能做到这一点?
增加了一个答案。 – insomiac