fmpq.com
源代码:
点击运行
<!DOCTYPE html> <html> <body> <p>点击按钮修改图片的颜色为黑白 (100% 灰度)。</p> <button onclick="myFunction()">尝试一下</button><br> <img id="myImg" src="/images/htmlcss/pineapple.jpg" alt="Pineapple" width="300" height="300"> <p><strong> 注意:</strong> IE 或 Firefox 浏览器不支持该属性。</p> <script> function myFunction() { document.getElementById("myImg").style.WebkitFilter = "grayscale(100%)"; // Chrome, Safari, and Opera } </script> </body> </html>
运行结果