For loop help in javascript?
本问题已经有最佳答案,请猛点这里访问。
JS代码
1 2 3 4 5 6 7 8 9 10 | <script type="text/javascript"> var list = document.getElementsByClassName('sortByTestName'); for (var i = 0; i < list.length; i++) { var current = list[i].innerHTML; list[i].onclick = function() { window.alert(current); } } |
好的,这里的代码通过
<但是>
1 2 3 4 5 6 7 | var list = document.getElementsByClassName('sortByTestName'); for (var i = 0; i < list.length; i++) { list[i].onclick = function() { window.alert(this.innerHTML); } } |
1 2 3 | div:hover { cursor: pointer; } |
1 2 3 4 | <span>Here is some inner html</span> <span>Some more inner html</span> |
<铅>