Помогите решить задачу по JQuery [закрыт]

206
06 августа 2018, 02:50

Дан инпут, в который можно ввести число. Сделайте так, чтобы при вводе числа в этот инпут и потери фокуса на странице искался чекбокс с таким номером и становился отмеченным, а остальные чекбоксы становились неотмеченными.

Answer 1

$("input[type='number']").blur(function () { 
  $("input[type='checkbox']").prop('checked', false).eq($(this).val()-1).prop('checked', true) 
})
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script> 
 
<input type=number min=1><br> 
<input type=checkbox><input type=checkbox><input type=checkbox><input type=checkbox><input type=checkbox><input type=checkbox><input type=checkbox><input type=checkbox><input type=checkbox><input type=checkbox><input type=checkbox><input type=checkbox><input type=checkbox><input type=checkbox><input type=checkbox><input type=checkbox><input type=checkbox><input type=checkbox><input type=checkbox><input type=checkbox><input type=checkbox><input type=checkbox><input type=checkbox><input type=checkbox><input type=checkbox><input type=checkbox><input type=checkbox><input type=checkbox><input type=checkbox><input type=checkbox><input type=checkbox><input type=checkbox><input type=checkbox><input type=checkbox><input type=checkbox><input type=checkbox><input type=checkbox><input type=checkbox><input type=checkbox><input type=checkbox><input type=checkbox><input type=checkbox><input type=checkbox><input type=checkbox><input type=checkbox><input type=checkbox><input type=checkbox><input type=checkbox><input type=checkbox><input type=checkbox><input type=checkbox><input type=checkbox><input type=checkbox><input type=checkbox><input type=checkbox><input type=checkbox><input type=checkbox><input type=checkbox><input type=checkbox><input type=checkbox><input type=checkbox><input type=checkbox><input type=checkbox><input type=checkbox><input type=checkbox><input type=checkbox><input type=checkbox><input type=checkbox><input type=checkbox><input type=checkbox><input type=checkbox><input type=checkbox><input type=checkbox><input type=checkbox><input type=checkbox><input type=checkbox><input type=checkbox><input type=checkbox><input type=checkbox><input type=checkbox><input type=checkbox><input type=checkbox><input type=checkbox><input type=checkbox><input type=checkbox><input type=checkbox><input type=checkbox><input type=checkbox><input type=checkbox><input type=checkbox>

Answer 2

Если номер чекбокса - в его id(например, id="check_1") и класс всех чекбоксов class="check", тогда:

$('input').on('blur',function(event){
 var num=$(this).val();
 var id='check_'+num;
 $('.check').each(function(){
  (this).checked(false);
 });
 $(id).checked(true);
});
READ ALSO
Работа с классами jquery

Работа с классами jquery

Учу JSВ чем суть

136
Запись чисел в файл с разделением

Запись чисел в файл с разделением

День добрый, требуется записать в файл 5 чиселВопрос в том, как эти числа, считываемые с TextBox разделить запятой и вывести на новую строку в файл

165
Как сделать button в виде треугольника в WPF?

Как сделать button в виде треугольника в WPF?

Нашел множество примеров как сделать круглые кнопки, но не одного решения о том как сделать в виде треугольникаВозможно ли это, или лучше...

243
Сравнить 2 значения, старое и новое в Job

Сравнить 2 значения, старое и новое в Job

C# Консольное приложениеРеализована связка Topshelf+Quartz

151