与代码的其余部分分开的搜索词
Search terms separated from rest of the code?
$("[title*='A-title-im-not-interested-in']").closest("div.parentdivofproduct").attr("style","visibility: hidden !important; display: none !important;");
$("[title*='Second-title-no-need']").closest("div.parentdivofproduct").attr("style","visibility: hidden !important; display: none !important;");
$("[title*='Third-i-dont-want-to-see']").closest("div.parentdivofproduct").attr("style","visibility: hidden !important; display: none !important;");
$("[title*='4thtitle']").closest("div.parentdivofproduct").attr("style","visibility: hidden !important; display: none !important;");
我正在使用上面的代码来隐藏我不想要的标题。每个都在单独的行中,所有的东西都在重复有匹配时需要做的事情。有没有办法达到相同的结果,我可以将我的标题列在一个地方,并保持待办事项代码分开?像这样的东西?
$("[title*=MYTITLES]").closest("div.parentdivofproduct").attr("style","visibility: hidden !important; display: none !important;");
MYTITLES {'A-title-im-not-interested-in','Second-title-no-need','Third-i-dont-want-to-see','4thtitle'};
可以尝试类似的东西
var titles = ['title 1', 'title 2', 'title 3'];
$("[title]").filter(function(){
return titles.indexOf(this.title) >-1;
}).closest("div.parentdivofproduct").attr("style","visibility: hidden !important; display: none !important;");
或
$.each(titles, function(_, title){
$('[title="' + title + '"]').closest("div.parentdivofproduct").attr...
})
或
var selector = titles.map(function(title){
return '[title="' + title + '"]';
}).join()
$(selector).closest("div.parentdivofproduct").attr...
不能使用包含多个元素的数组来创建单个 jQuery 选择。相反,您需要使用具有不同查询的每个元素遍历数组。
所以你可以使用任何从 for 循环、$.map
、$.each
、Array.prototype.forEach
或Array.prototype.every
......等
相关文章:
- 用程序搜索JQuery数据表中的文本
- 在html Select中添加搜索
- Ajax Live搜索发布到Laravel视图
- 谷歌放置API:按国家或餐馆名称搜索餐馆
- 学生搜索项目jquery/javascript
- 用于搜索的聚合物嵌套绑定
- 在javascript中搜索具有重复值的两个数组中的匹配值
- Angularjs-utils高亮过滤器在搜索时破坏应用程序
- 使用javascript搜索具有用户输入的数组
- 淘汰搜索/筛选
- 搜索api在mac上显示对话框
- AngularJS/HTML/Bootstrap元素用于动态搜索结果
- 谷歌水印未显示在自定义搜索框中
- 在javascript中搜索项目列表的性能
- 正在搜索JavaScript日期选择器滑块
- JQuery中的活动搜索栏
- 如何在剑道下拉列表中按文本和值搜索
- 谷歌CSE-搜索参数
- 如何让typeahead在我的搜索栏中填充自定义参数
- 如何使用提交按钮搜索表中的记录