当在任何jam
输入中键入值时,我想使用onkeyup
处理程序仅获取生成事件的jam
输入的值。然后我想用它来仅修改它下面的Menit
输入,而不是全部。
这是我的代码:
$(document).on("keyup", ".jam", function hitung_jam() {
var jam = $(this).val();
var waktu_jam = jam * 60;
$(this).nextAll(".menit").first().val(waktu_jam);
});

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<form method="POST" action="">
<table>
<tr>
<td> KE 1 </td>
<td> Jam <input type="text" class="jam" autocomplete="off"></td>
<td> Menit <input type="text" class="menit"> </td>
</tr>
<hr>
<tr>
<td> KE 1 </td>
<td> Jam <input type="text" class="jam" autocomplete="off"></td>
<td> Menit <input type="text" class="menit"> </td>
</tr>
</table>
</form>
&#13;
答案 0 :(得分:0)
这适用于包含表格的HTML。
$(document).on("keyup", ".jam", function hitung_jam() {
var jam = $(this).val();
var waktu_jam = jam * 60;
$(this).closest('tr').find('.menit').val(waktu_jam);
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<form method="POST" action="">
<table>
<tr>
<td> KE 1 </td>
<td> Jam <input type="text" class="jam" autocomplete="off"></td>
<td> Menit <input type="text" class="menit"> </td>
</tr>
<hr>
<tr>
<td> KE 1 </td>
<td> Jam <input type="text" class="jam" autocomplete="off"></td>
<td> Menit <input type="text" class="menit"> </td>
</tr>
</table>
</form>
答案 1 :(得分:0)
browserNameVariable
答案 2 :(得分:0)
你可以使用兄弟姐妹:
<main>
<section>Lorem ipsum dolor sit amet, consectetur adipisicing elit. A totam temporibus beatae veritatis ipsam, necessitatibus quibusdam dolorem molestias assumenda! Aut maiores magni ratione libero quisquam omnis, iure ab reprehenderit dolore.</section>
<ul>
<li><a href="#">1</a></li>
<li><a href="#">2</a></li>
<li><a href="#">3</a></li>
<li><a href="#">4</a></li>
</ul>
</main>