源代码
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>编程字典</title> <script> function showDetails(animal) { var animalType = animal.getAttribute("data-animal-type"); alert("The " + animal.innerHTML + " is a " + animalType + "."); } </script> </head> <body> <h1>物种</h1> <p>选择一个物种看看他们的类型:</p> <ul> <li onclick="showDetails(this)" id="owl" data-animal-type="鸟类">猫头鹰</li> <li onclick="showDetails(this)" id="salmon" data-animal-type="鱼类">三文鱼</li> <li onclick="showDetails(this)" id="tarantula" data-animal-type="蜘蛛">狼蛛</li> </ul> </body> </html>
运行结果