zbwroom的博客通过本文主要向大家介绍了js面试题等相关知识,希望对您有所帮助,也希望大家支持linkedu.com www.linkedu.com
<html lang="en"> <head> <meta charset="UTF-8"> <title>Document</title> </head> <body> <div id="cc" someAttr='itany'>cc</div> <table> <tr> <td id="td" colspan="2">ccc</td> </tr> </table> <script> var cc = document.getElementById('cc'); console.log( cc.someAttr ); // undefined console.log( cc.getAttribute('someAttr') ); // itany console.log( document.getElementById('cc').colspan ); // undefined // 解析: // 1. dom对象不能直接取自定义的属性值 // 2. getAttribute() 方法返回指定属性名的属性值。 // 3. dom操作不能获取html的属性值 </script> </body> </html>