【发布时间】:2020-06-18 00:40:07
【问题描述】:
希望根据生成的下拉选择动态 id 启用文本框。文本框和选择框 id 是动态生成的,如 ..amount1、amount2、amount3 并在最大为 3000 数量的文本框上应用验证。例如:当用户选择时,文本框值中的“罚款”值应允许在 1 到 3000 和文本之间。如果选择“罚款”以外的值,则在文本框上不进行验证。
我的 Javascript 代码:
var $ = jQuery;
$(document).ready(function() {
$('.amount').attr('disabled', true);
$(".amount").css({ "backgroundColor": "#eee" });
});
$(document).ready(function () {
$('input[name=amount]').keyup(function () {
var total_items = 100;
for (rowNum = 1; rowNum <= total_items; rowNum++) {
var selectvl = $("#exp_id" + rowNum).val();
if (selectvl == '10') {
if ($(this).val() < 3001 && $(this).val() > 1) {
$('#msg').fadeOut('slow');
} else {
$('#msg').fadeIn('slow');
}
}
}
});
$('body').on('change', '.exp_id', function () {
var total_items = 100;
for (rowNum = 1; rowNum <= total_items; rowNum++) {
const toChangeElement = $(event.target).parent().next().children();
const exp_id = event.target.value;
if (this.value == '10') {
$("#amount" + rowNum).attr('max', '3000');
$("#amount" + rowNum).attr('min', '1');
$('#msg').fadeIn('slow');
$("#msg").html("Enter amount below AED 3000. !!");
$("#amount" + rowNum).css({ "backgroundColor": "#ffffff" );
toChangeElement.removeAttr('disabled');
toChangeElement.css('backgroundColor', "#ffffff");
toChangeElement.focus();
return false;
} else {
$('#msg').fadeOut('slow');
$("#amount" + rowNum).attr('max', '10000');
$("#amount" + rowNum).attr('min', '1');
$("#amount" + rowNum).css({"backgroundColor": "#ffffff"});
toChangeElement.removeAttr('disabled');
toChangeElement.css('backgroundColor', "#ffffff");
toChangeElement.focus();
}
}
});
});
【问题讨论】:
标签: jquery html jquery-ui jquery-plugins