使用jQuery隐藏选择列表中的选项 [英] Hide options in a select list using jQuery
本文介绍了使用jQuery隐藏选择列表中的选项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个对象,该对象具有要从选择列表中隐藏/删除的选项的键/值对. 以下两个选项选择器都不起作用.我想念什么?
I have an object with key/value pairs of options I want to hide/remove from a select list. Neither of the following option selectors work. What am I missing?
$.each(results['hide'], function(name, title) {
$("#edit-field-service-sub-cat-value option[value=title]").hide();
$("#edit-field-service-sub-cat-value option[@value=title]").hide();
});
推荐答案
就其价值而言,jQuery 1.3中不存在第二种形式(带有@
).第一个不起作用,因为您显然期望变量插值.试试这个:
For what it's worth, the second form (with the @
) doesn't exist in jQuery 1.3. The first isn't working because you're apparently expecting variable interpolation. Try this:
$("#edit-field-service-sub-cat-value option[value=" + title + "]").hide();
请注意,如果title
包含jQuery选择器元字符,这可能会以各种丑陋的方式破坏.
Note that this will probably break in various hideous ways if title
contains jQuery selector metacharacters.
这篇关于使用jQuery隐藏选择列表中的选项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文