Javascript 删除一些<;李>;如果文本包含特定的文本
有人能帮我吗。Javascript 删除一些<;李>;如果文本包含特定的文本,javascript,jquery,arrays,Javascript,Jquery,Arrays,有人能帮我吗。 我知道这很简单,但我做不到 我试图在我的网站上隐藏一些包含特定文本的行(不应该出现)。 到目前为止,我所做的都在下面的代码中,但它不起作用。我所能做的就是使用.remove()进行操作,但它会弄乱数组 var shouldNotAppear = ['text1', 'text2', 'text3']; for (var i in $(".brand li h4 .option-title")) { if (shouldNotAppear.indexOf
我知道这很简单,但我做不到 我试图在我的网站上隐藏一些包含特定文本的行(不应该出现)。 到目前为止,我所做的都在下面的代码中,但它不起作用。我所能做的就是使用.remove()进行操作,但它会弄乱数组
var shouldNotAppear = ['text1', 'text2', 'text3'];
for (var i in $(".brand li h4 .option-title")) {
if (shouldNotAppear.indexOf($(".brand li h4 .option-title")[i].innerText) != -1) {
$(".brand h4")[i].hide();
};
$('.brand li h4.options title')。每个(…)
都比您正在使用的中的更合适。您能用它修复上面的代码吗?这对我有很大帮助
var shouldNotAppear = ['text1', 'text2', 'text3'];
$('.brand li h4 .option-title')
// filter to only the titles that have a value that should not appear
.filter(function(){ return shouldNotAppear.includes(this.innerText); })
// for each title that should not appear, go up to their parent h4
.closest('h4')
// hide them
.hide();