1

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

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

有什么聪明的方法吗?

PS。variableInteger 值来自另一个表单元素,其名称也仅在运行时才知道。

4

1 回答 1

8

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

select.children("option").filter(function() {
    return this.value > variableInteger;
}).prop("disabled", true);
于 2013-10-03T13:32:10.950 回答