<script src="http://libs.baidu.com/jquery/2.0.0/jquery.min.js"></script> <style> body { background: #f2f2f2; } * { margin: 0; padding: 0; border: 0; } .Speedometer{ width: 100%; height: auto; margin-top: 15px; display: inline-flex; } .Speedometer .SpeeBox{ width: 224px; height: 110px; margin-left: 1.15%; list-style: none; border-radius: 8px; text-align: center; background: #ffffff; display: inline-block; } .Speedometer .SpeeBox a{ width: 100%; height: 73px; color: #313242; font-size: 18px; line-height: 73px; display: inline-block; text-decoration: none; } .Speedometer .SpeeBox div { width: 100%; color: #fff; height: 39px; font-size: 16px; line-height: 39px; background: #313242; border-radius: 0 0 10px 10px; } </style> <ul class="Speedometer"> <li class="SpeeBox"> <a target="_blank" href="https://www.baidu.com/"> 线路入口一 </a> </li> <li class="SpeeBox"> <a target="_blank" href="https://www.so.com/"> 线路入口二 </a> </li> <li class="SpeeBox"> <a target="_blank" href="https://cn.bing.com/"> 线路入口三 </a> </li> <li class="SpeeBox"> <a target="_blank" href="https://www.sogou.com/"> 线路入口四 </a> </li> </ul> <script> // 定义全局函数 testResult function testResult(img) { const span = img.parentNode; const timeTaken = ((new Date() - span.ctime) / 1000).toFixed(2); if (!testResult.isrun) { testResult.isrun = true; span.style.backgroundColor = "#F1010A"; span.innerHTML = `<font id="kkk" color="#ffffff" style="font-weight:bolder">${timeTaken}秒 最快</font>`; } else { span.innerHTML = `${timeTaken}秒`; } } document.addEventListener('DOMContentLoaded', function() { const lis = document.querySelectorAll(".SpeeBox"); lis.forEach(li => { const a = li.querySelector('a'); if (a) { const span = document.createElement('div'); span.ctime = new Date(); span.innerHTML = `测速中...<img src="${a.href}" border="0" width="1" height="1" onerror="testResult(this)" />`; li.appendChild(span); } }); }); </script>