给你个dom参考吧 <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta http-equiv="X-UA-Compatible" content="ie=edge"> <title>Document</title> <style> *{ margin: 0; padding: 0; } .box{ display:inline-block; } .box .snake{ animation: rotate .8s infinite linear; border: 4px solid transparent; border-radius: 50%; border-top-color: rgb(204, 204, 204); border-left-color: rgb(204, 204, 204); border-bottom-color: rgb(204, 204, 204); height: 24px; width: 24px; } .btn{ background-color: #000; border: none; border-radius: 4px; padding: 3px 8px; outline: none; cursor: pointer; line-height: 36px; height: 36px; color: #ffffff; font-size: 16px; } @keyframes rotate{ 0% { transform: rotate(0deg); } 100% { transform: rotate(1turn); } } </style> </head> <body> <button class="btn"> 按钮 </button> </body> <script> var btn = document.querySelector(".btn"); btn.onclick = function(){ this.innerHTML = `<span class="box"> <div class="snake" ></div> </span>`; this.setAttribute("disabled",true); } </script> </html>
给你个dom参考吧