在我的页面中,我希望在元素悬停时显示子元素时产生效果。你能帮助使代码更好吗?
<!DOCTYPE HTML>
<html lang="en">
<head>
<meta charset="UTF-8">
<title></title>
<style type="text/css">
#list a { text-decoration: none; color: green; margin-right: 30px; }
#content { margin-top: 30px; }
#content a { text-decoration: none;margin-right: 10px; }
#content span.first1 { display: none; }
#content span.first1 { display: none; }
.show { display: inline; }
</style>
<script src="../jquery-1.10.min.js" type="text/javascript"></script>
<script type="text/javascript">
$(document).ready(function() {
$('#list a').hover(function() {
hover_hidden()
})
function hover_hidden() {
var length = $('#first a').length
var str = '
for(i=0; i<length; i++) {
if ( i == 0)
$('.first').show()
else {
$('#list a').eq(i).hover(function() {
$('.first').hide()
var str = '.first'
i += ''
var newdetail = str + i
// alert(newdetail)
$("newdetail").addClass('show')
})
}
}
}
})
</script>
</head>
<body>
<div id="list">
<a href="#">first</a>
<a href="#">second</a>
<a href="#">three</a>
</div>
<div id="content">
<span class="first">
<a href="#">first</a>
<a href="#">first</a>
<a href="#">first</a>
</span>
<span class="first1">
<a href="#">second</a>
<a href="#">second</a>
<a href="#">second</a>
</span>
<span class="first2">
<a href="">three</a>
<a href="">three</a>
<a href="">three</a>
</span>
</div>
</body>
</html>
我把代码放在这里http://jsfiddle.net/DVdAk/