JS的点击事件怎么优化

<!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>


慕雪1402187
浏览 2194回答 2
2回答
打开App,查看更多内容
随时随地看视频慕课网APP