值大于(小于)变量的 jQuery 过滤器选项

jQuery filter options with value greater (less) than variable

本文关键字:jQuery 过滤器 选项 变量 大于 小于      更新时间:2023-09-26

我需要禁用选择中小于某个数字的选项值,我事先不知道(它是在另一个表单元素中设置的)。我需要类似下面的代码,但变量值为"变量整数":

select.children().filter(function() {
  return $(this).attr("value") > variableInteger;
}).each(function () {$(this).attr('disabled', 'disabled')});

有什么聪明的方法可以做到这一点吗?

变量整数值来自另一个表单元素,该名称也仅在运行时已知。

不需要.each,也可以使用propthis.value(不需要$(this).attr("value");

select.children("option").filter(function() {
    return this.value > variableInteger;
}).prop("disabled", true);