gpt4 book ai didi

javascript - 如何制作唯一的div id?

转载 作者:行者123 更新时间:2023-11-28 13:51:30 25 4
gpt4 key购买 nike

这是我的 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'); ?>

最佳答案

您忘记增加i变量:

   ...
});
i++;
}
while(i<=5);

关于javascript - 如何制作唯一的div id?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10536439/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com