douzheng9221 2013-03-30 09:38
浏览 85
已采纳

在jquery脚本中获取页面加载的ID

I have a PHP while loop where I am generating #id dynamically.

Example :

<?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: 
?>

The status id are generating like this : status1, status2, status3 etc...

I want all these Id's in my JS code ON LOAD for displaying it into the modal dialog.

Example :

<script type="text/javascript">

$(document).ready(function(){

$("#status1");
$("#status2");
$("#status3");
.
.
and so on as per the php while loop.

});
</script>

How can I achieve this?

  • 写回答

3条回答 默认 最新

  • duanhui1869 2013-03-30 09:43
    关注

    You could use the "Starts With" selector:

    $('td[id^="status"]').each(function(index){
       alert($(this).attr("id"));
    });
    

    You can specify scope of selector in order to target main td's

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 stm32开发clion时遇到的编译问题
  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)
  • ¥15 Vue3地图和异步函数使用
  • ¥15 C++ yoloV5改写遇到的问题
  • ¥20 win11修改中文用户名路径
  • ¥15 win2012磁盘空间不足,c盘正常,d盘无法写入
  • ¥15 用土力学知识进行土坡稳定性分析与挡土墙设计
  • ¥70 PlayWright在Java上连接CDP关联本地Chrome启动失败,貌似是Windows端口转发问题
  • ¥15 帮我写一个c++工程
  • ¥30 Eclipse官网打不开,官网首页进不去,显示无法访问此页面,求解决方法