源代码:
下载代码
AI 编程工具
点击运行
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>菜鸟教程(runoob.com)</title> </head> <body> <h1>item() 方法</h1> <p>点击按钮返回 id 为 ex1 元素对应样式的第一个属性名:</p> <div id="ex1" style="color:blue; font-family:monospace;">一些文本</div> <button onclick="myFunction()">点我</button> <script> function myFunction() { var style = document.getElementById('ex1').style; var propname = style.item(0); alert(propname); } </script> </body> </html>
运行结果: