我需要 -
- 在加载 DOM 内容时创建引导图标(心形)
- 单击图标时,心形图标填充为红色(这里我使用心形填充图标)
- 两个图标都比原来的大
document.addEventListener('DOMContentLoaded', function () {
var heart = document.createElement('i')
heart.className = 'bi bi-heart'
document.querySelector('#posts').append(heart)
heart.onclick = function () {
this.className = 'bi bi-heart-fill'
this.setAttribute('fill', 'red')
}
} )
<head><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.5.0/font/bootstrap-icons.css"></head>
<body><div id="posts"></div></body>
当我点击心脏时,它充满了黑色,而不是红色。我也不知道如何通过增加宽度和高度的值来使其更大。我看到了与此相关的其他问题,但没有一个能解决我的问题。