如何爲由foreach循環生成的每個按鈕創建特定的Jquery操作?由foreach循環生成的每個按鈕的Jquery特定操作
<script type="text/javascript">
$(document).ready(function() {
$("#numero").hide();
$("#shownum").click(function(){
$("#numero").toggle();
});
});
</script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<?php foreach ($annonces as $key => $annonce) : ?>
<button type="button" class="btn btn-primary btn-xs" id="shownum"> <span class=" glyphicon glyphicon-earphone" aria-hidden="true"> </span> show/hide</button>
<div id="numero">
<?php echo $annonce['Annonce']['title'] ;?>
</div>
<?php endforeach; ?>
改爲使用類。 – mplungjan