我有一个PHP while循环,可以动态生成#id。
范例:
<?php
$i=1;
while ($row = mysqli_fetch_array($result)):
?>
<tr>
<td class='hashtag' id='status<?php echo $i; ?>'>status value</td>
</tr>
<?php
$i++;
endwhile:
?>
状态ID生成如下:status1,status2,status3等。
我希望所有这些ID在我的JS代码加载中显示在模式对话框中。
范例:
<script type="text/javascript">
$(document).ready(function(){
$("#status1");
$("#status2");
$("#status3");
.
.
and so on as per the php while loop.
});
</script>
我该如何实现?
最佳答案
您可以使用“ Starts With”选择器:
$('td[id^="status"]').each(function(index){
alert($(this).attr("id"));
});
您可以指定选择器的范围,以便定位主要td