在話語分類頁面有一個類,我可以使用類::after上的內容添加自定義文本,但這個函數在所有圖像上創建文本,因為所有圖像都有相同的類。類別-徽標。方面-圖像img,我想在所有類別下添加獨特的文本,我寫了這段代碼,但它只有在重新加載頁面后才能工作。請支持
<script>
document.addEventListener("DOMContentLoaded", function() {
$(function() {
var categories = [
{
logoUrl: "/uploads/",
line1: "ATALANTA, USA",
line2: "<a style='color: #646464;'>WWW.ATALANTA.COM</a>"
},
{
logoUrl: "/uploads", // Replace with actual image URL for Category 2
line1: "Denver, United States",
line2: "<a style='color: #646464;'>WWW.ATALANTA.COM</a>"
},
// Add more objects for other categories
{
logoUrl: "/uploads", // Replace with actual image URL for Category 2
line1: "Dowman Drive, Atalanta",
line2: "<a style='color: #646464;'>WWW.ATALANTA.COM</a>"
},
{
logoUrl: "/uploads", // Replace with actual image URL for Category 2
line1: "ATALANTA, USA",
line2: "<a style='color: #646464;'>WWW.ATALANTA.COM</a>"
},
{
logoUrl: "/uploads", // Replace with actual image URL for Category 2
line1: "ATALANTA, USA",
line2: "<a style='color: #646464;'>WWW.ATALANTA.COM</a>"
},
{
logoUrl: "/uploads", // Replace with actual image URL for Category 2
line1: "ATALANTA, USA",
line2: "<a style='color: #646464;'>WWW.ATALANTA.COM</a>"
},
];
$(".category-heading").each(function(index) {
var category = categories[index];
var $logoElement = $(this).find(".category-logo img");
var $descriptionElement = $("<p>")
.html(category.line1 + "<br>" + category.line2)
.addClass("custom99"); // Add your custom class name here
$logoElement.after($descriptionElement);
});
});
});
</script>
上一篇vue上傳視頻組件