簡體   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