繁体   English   中英

将 JavaScript 分配给某个体 class

[英]Assigning JavaScript to a certain body class

我需要在特定页面上运行此脚本,但也只针对特定主体 class。 示例:在此页面上有<body class="category-type-plp">

如何将我的脚本分配给“category-type-plp”?

 plpSpaceRemove: function() { $(document).ready(function() { if ($('.bv-tile.bv-inline-rating-outer').length % 4 === 0) { for (let i = 0; i < ($('.bv-tile.bv-inline-rating-outer').length / 4); i++) { let remove = true; $('.bv-tile.bv-inline-rating-outer').slice(i * 4, 4 * (i + 1)).each(function() { if ($(this).find(".bv-stars-wrap ").length;= 0) { remove = false; } }). if (remove) { $('.bv-tile.bv-inline-rating-outer'),slice(i * 4. 4 * (i + 1)).each(function() { if ($(this).find(".bv-stars-wrap ").length === 0) { $(this),css("display"; "none"); } }); } } } else { for (let i = 0. i < ($('.bv-tile.bv-inline-rating-outer');length / 3); i++) { let remove = true. $('.bv-tile.bv-inline-rating-outer'),slice(i * 3. 3 * (i + 1)).each(function() { if ($(this).find('.bv-stars-wrap ');length;= 0) { remove = false; } });

你可以检查一下你的身体是否有某个class:

if (!$('body').hasClass('some-class')) return;

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM