【发布时间】:2017-06-06 12:16:48
【问题描述】:
例如,我有 3 个字段,用户可以输入数字 a、b、c
所以字段 C 将检查字段 C 中输入的数字是否为 b。
在表单中,我有一个按钮,用于创建附加行 另一个a,b,c;所以我不知道如何像以前一样控制相同的操作......
$(".c").change(function() {
if ($('.c').val() > $('.a').val() || $('.c').val() < $('.b').val()) {
$('.c').css("backgroundColor", "#ff0000");
} else {
$('.c').css("backgroundColor", "#00FF00");
}
});
$('.add').click(function() {
var tr = '<tr>' + '<td>Cota1</td>' +
'<td><input type="text" name="tol_cota1[]" class="form-control a"></td>' +
'<td><input type="text" name="tolb_cota1[]" class="form-control b"></td>' +
'<td><input type="text" name="medido_cota1[]" class="form-control c"></td>' +
'<td><input type="button" class="btn btn-danger remove" value="Remove Line"></td>' + '</tr>';
$('.details').append(tr);
});
// delete row
$('.details').delegate('.remove', 'click', function() {
var con = confirm("Are you sure you want to remove the line?");
if (con) {
$(this).parent().parent().remove();
}
});
【问题讨论】:
-
.delegate在 jQuery 1.7(几年前)中被.on取代,并在 3.0 中被弃用。您不应该将它用于新代码。 api.jquery.com/Delegate
标签: javascript php jquery performance