标签:detail UNC 驼峰 spider str tar 否则 使用 微信小程序
背景
用法
<!DOCTYPE html> <html> <body> <ul> <li onclick="showDetails(this)" id="owl" data-animal-bird="bird">Owl</li> <li onclick="showDetails(this)" id="salmon" data-animal-fish="fish">Salmon</li> <li onclick="showDetails(this)" id="tarantula" data-animal-spider="spider">Tarantula</li> </ul> </body> </html>
<script> function showDetails(animal) { var animalBird = animal.dataset.animalBird; console.log(animalBird); //bird var animalFish = animal.dataset.animalFish; console.log(animalFish); // fish var animalSpider = animal.dataset.animalSpider; console.log(animalSpider); //spider } </script>
<script> function showDetails(animal) { var animalBird= animal.getAttribute("data-animal-bird"); console.log(animalBird);--bird var animalFish = animal.getAttribute("data-animal-fish"); console.log(animalFish );--fish var animalSpider = animal.getAttribute("data-animal-spider"); console.log(animalSpider );--spider } </script>
注意事项
<html> <body> <ul> <li onclick="showDetails(this)" id="owl" data-animalbird="bird">Owl</li> </ul> </body> </html> <script> function showDetails(animal) { var animalBird = animal.dataset.animalbird; console.log(animalBird); //bird } </script>
<html> <body> <ul> <li onclick="showDetails(this)" id="owl" data-animal-bird="bird">Owl</li> </ul> </body> </html>
<script> function showDetails(animal) { var animalBird = animal.dataset.animalBird; //驼峰式命名,否则报错undefined console.log(animalBird); //bird } </script>
标签:detail UNC 驼峰 spider str tar 否则 使用 微信小程序
原文地址:https://www.cnblogs.com/zuiyue_jing/p/12155772.html