<label id = "1" onclick="ishow(this);" data-text = "单词的意思" >点击查看</label>
第一种:
<script> function ishow(obj){ var t = obj.innerHTML; obj.innerHTML = $(obj).data("text"); $(obj).data("text", t); } </script>
第二种:
<script> function ishow(obj){ var test = obj.getAttribute("data-text"); alert(obj.innerHTML + ";" + test); obj.setAttribute("data-text", obj.innerHTML); obj.innerHTML = test; } </script>
类似:
<!DOCTYPE html> <html> <head> <script> function showDetails(animal) { var animalType = animal.getAttribute("data-animal-type"); alert(animal.innerHTML + ";" + animalType); animal.setAttribute("data-animal-type", animal.innerHTML); animal.innerHTML = animalType; } </script> </head> <body> <h1>物种</h1> <p>点击某个物种来查看其类别:</p> <ul> <li onclick="showDetails(this)" id="owl" data-animal-type="鸟类">喜鹊</li> </ul> </body> </html>