为了账号安全,请及时绑定邮箱和手机立即绑定

JS的点击事件怎么优化

JS的点击事件怎么优化

慕雪1402187 2017-09-14 12:05:32
<!DOCTYPE html><html> <head> <meta charset="UTF-8"> <title></title> <link rel="stylesheet" type="text/css" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css"/> </head> <body> <div class="container"> <ul class="nav nav-tabs"> <li id="li1" class="active"><a href="#">11111</a></li> <li id="li2"><a href="#">11111</a></li> <li id="li3"><a href="#">11111</a></li> </ul> </div> <script type="text/javascript"> var oLi1 = document.getElementById('li1') var oLi2 = document.getElementById('li2') var oLi3 = document.getElementById('li3') oLi1.onclick = function(){ oLi1.className ='active' oLi2.className ='' oLi3.className ='' } oLi2.onclick = function(){ oLi2.className ='active' oLi1.className ='' oLi3.className ='' } oLi3.onclick = function(){ oLi3.className ='active' oLi2.className ='' oLi1.className ='' } </script> </body></html>
查看完整描述

2 回答

  • 2 回答
  • 0 关注
  • 2192 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信