Я хочу проверить несколько полей ввода. Код ниже работает отлично, за исключением метода фокуса. Я ожидаю, что он не сможет интерпретировать «входную» переменную, которая относится к входному местоположению в форме. Вопрос: Как я могу указать местоположение конкретного входа, учитывая, что имеется более 20 входов? tks!Как ссылаться на «это» в функции
function validateInput(quantity,input)
{
if (quantity.value !== " ") {
if(isNaN(quantity)) {
$(".myerror_alert").append('<div class="alert alert-danger"><strong>Warning!</strong> You have entered an non valid character, go back and enter a real number </div>');
input.focus(); // THIS DOES NOT WORK
return false;
}
}
return true;
}
$(".product_table").on('change', '.edit_quantity',function(){
var quantity = $(this).parents(':eq(1)').find('input').filter(".edit_quantity").val();
var input = $(this).parents(':eq(1)').find('quantity').filter(".edit_quantity");
validateInput(quantity, input);
// MORE CODE GOES HERE //
});
HTML:
<tr class='delete_row'>
<td><input class="product_id form-control" readonly="readonly" name="product_id[0]" type="text" value="123"></td>
<td><input class="edit_product_id form-control" readonly="readonly" name="product_id[0]" type="text" value="Euroshake Blackstone"></td>
<td><input class="edit_quantity" name="product_id[0]" type="text" value="120"></td>
<td id="price"><input class="unit_price form-control" readonly="readonly" style="text-align:right;" name="price" type="text" value="120.00"></td>
<td><input class="line_cost form-control" readonly="readonly" style="text-align:right;" name="cost" type="text" value="14400.00"></td>
<td>
<span style="padding-left:12px;"><input name="delete" type="checkbox" value="123"></span>
</td>
</tr>
Можете ли вы поделиться своим HTML? – LinkinTED
Вы не показываете, где вы называете 'validateInput', поэтому мы не знаем, что вы передаете в качестве параметров. Он должен работать, если 'input' является объектом jquery – dan08
вы пробовали' $ (input) .focus() '? Кроме того, сеем наш html, где вы вызываете 'validateInput' –