<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title></title> <style> ul { list-style-type: none; cursor: pointer; } </style> </head> <body> <ul> <li score="60">张三的数学成绩</li> <li score="90">赵四的数学成绩</li> <li score="90">王五的数学成绩</li> <li score="80">唐七的数学成绩</li> <li score="50">宋八的数学成绩</li> </ul> <script src="common.js"></script> <script> var list = document.getElementsByTagName("li"); for (var i = 0; i < list.length; i++) { list[i].onclick = function () { // alert(this.score);//弹出undefined alert(this.getAttribute("score")); }; } </script> </body>
原文:https://www.cnblogs.com/jane-panyiyun/p/11991236.html