这是我的html标记......问题是javascript循环不起作用......我犯了一些错误......我不知道为什么......我想循环$('#opt_art').mouseover等...... . 并且每个循环都使脚本像第一个循环 $('#opt_art1).mouseover,第二个循环 $('#opt_art2).mouseover 等
<?php include('header.php'); ?>
<script type="text/javascript">
$(document).ready(function(){
var i = 0;
do{
var num = i;
$('#opt_art'+num).mouseover(function(){
$('.opsi'+num).show();
});
$('#opt_art'+num).mouseout(function(){
$('.opsi'+num).fadeOut(2000);
});
i++;
}
while(i<=2);
});
</script>
<?php
for($i=1;$i<=2;$i++){
?>
<div id="art_category"><p>News</p></div><!-- end of category -->
<div id="art_title"><p>Sherlock Holmes 2</p></div><!-- end of art_title -->
<div id="rounded_artikel">
<li><img src="images/42897.jpg" width="110" height="110" class="art_image"/></li>
<ul><li><p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec bibendum bibendum magna at egestas. Sed commodo gravida arcu id accumsan. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Quisque vulputate, velit vitae pellentesque condimentum, lectus mi tempor nisl, sed sagittis est massa eu justo. Cras sed quam sed mauris elementum consectetur. Nunc vitae tortor diam, in hendrerit risus. Nulla et diam non libero vehicula blandit. Etiam facilisis, risus mattis venenatis iaculis, risus dolor lobortis sapien, a malesuada magna nibh nec tellus. Integer viverra, sapien quis pellentesque lobortis, tellus erat mattis nulla, vitae laoreet erat dolor sed ante.</p></ul></li>
</div><!-- end of rounded_artikel -->
<div id="art_info">
<img src="images/communication-icon.png" width="23" height="23" class="comment"/><li class="total_komentar"><a href="#">123</a> Komentar</li>
<img src="images/40395696544694793.png" width="23" height="21" class="art_date_icon"/><li class="art_date">19-06-2012</li>
<img src="images/1903484911.png" width="23" height="21" class="author_icon"/><li class="author">straw_hat</li>
<div id="opt_art<?=$i;?>">Option<?php echo $i; ?></div>
<div class="opsi<?=$i;?>"><center><a href="#">Readmore</a> | <a href="#">Comment</a></center></div>
</div><!-- end of art_info -->
<?php } ?>
<?php include('footer.php'); ?>