Jquery 显示所有不带';不包含值hello_
因此,我希望能够隐藏所有选项,然后仅显示其值中不包含Jquery 显示所有不带';不包含值hello_,jquery,Jquery,因此,我希望能够隐藏所有选项,然后仅显示其值中不包含hello\uu的选项。这包括hello\u bye,hello\u hello等。任何以hello\u开头的内容 这就是我到目前为止所做的: jQuery(document).ready(function(){ jQuery("#metakeyselect > option").hide(); jQuery("#metakeyselect > option[//what goes here?//]").show()
hello\uu
的选项。这包括hello\u bye
,hello\u hello
等。任何以hello\u开头的内容
这就是我到目前为止所做的:
jQuery(document).ready(function(){
jQuery("#metakeyselect > option").hide();
jQuery("#metakeyselect > option[//what goes here?//]").show();
});
如何显示除包含hello\ux值的选项以外的所有内容?
包含你好的元素
:
$("#metakeyselect > option:contains('hello_')")
$("#metakeyselect > option:not(:contains('hello_'))")
不包含你好的元素
:
$("#metakeyselect > option:contains('hello_')")
$("#metakeyselect > option:not(:contains('hello_'))")
您可以使用“隐藏”其值以hello\uu
开头的值
正如正确指出的,并非所有浏览器都允许您隐藏选项元素(另请参见)。但您可以删除它们:
var hidden_options = jQuery("#metakeyselect > option[value^=hello_]").remove();
或禁用它们:
jQuery("#metakeyselect > option[value^=hello_]").prop('disabled', true);
取决于您还想用它们做什么。您可以使用:
$(document).ready(function(){
var options = $('#metakeyselect > option');
var contains = "hello_";
options.each(function() {
if($(this).val().indexOf(contains) != -1){
$(this).remove();
}
});
});
或
您需要对选项使用remove()。所说的“值”是指选项元素的value
属性或文本内容?选项[value='blah']valueAh,然后使用Felix的答案。@Zenith,因为我只粘贴了部分问题。实际上我在我的主题中玩弄WordPress的核心,这不会检查条件:“任何开始的东西”那么这是否像正则表达式一样工作,任何以hello\u
开头的东西都会被删除?@Edmund:每个选项元素的值属性都以hello\u
开头,是的。