jQuery的函数不依赖于另一个控件的值

jQuery not function dependency on the value of another control

本文关键字:控件 另一个 函数 jQuery 依赖于      更新时间:2023-09-26

我有以下代码:

$(serialNumbersDDL).children("option:gt(0)").remove();

它将删除除第一个选项外的所有选项。现在我需要删除除第一个选项外的所有选项,也不删除值等于标签文本的选项。在编写数量有限的代码的情况下,我怎么能这么说呢?

尝试

$("option:not(':first')",serialNumbersDDL).filter(function(){
return $(this).val()!=$(this).text();
}).remove();

我会试试

$(serialNumbersDDL).children("option:gt(0)").not(function(){
    return $(this.labels).text() == this.value;
}).remove();