<div class="todo-task">
<input type="checkbox" id=' checkbox1' />
<label for='checkbox1 '> hellooooo <span class="todo-remove mdi-action-delete"></span>
</label>
</div>
当我单击跨度项目时,我想要复选框的ID值。我怎么才能得到它?
最佳答案
遍历到一个也包含复选框的已知父级,找到该复选框,然后获取ID属性。
$('span.todo-remove').on('click', function() {
var id = $(this).closest('.todo-task').find('input:checkbox').attr('id');
// do something with id
});
关于javascript - 如何通过单击跨度获取最接近的复选框项目的ID,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/32056477/