dsdt66064367 2016-04-09 16:16
浏览 34

无法使用jquery在td类中获取值

I am new to web development and one thing that is driving my head mad is that I am unable to get the value for one of the values in my table.

At present this is my code:

<?php
...
if(($result->num_rows)>0){
    while($row = $result->fetch_assoc()){
        print
        "<tr>".
            "<td id='numbers' class='col-md-4 text-center'>{$row["number"]}</td>".
            "<td class='col-md-1 text-center'>$row["names"]</td>".
        "</tr>";
    }
?>

<script type="text/javascript">
        var jz = $('#numbers').val();
        alert(jz);
</script>

I am using bootstrap so I am probably not setting the ID properly for the td tag. Nothing is being returned for the #numbers. I don't get why

Would mean a lot if someone could help me out

Thanks

  • 写回答

1条回答 默认 最新

  • dongyan1993 2016-04-09 16:18
    关注

    It's not .val(), use .text() or .html() instead. .val() is used on input fields like textarea.

    http://api.jquery.com/val/

    http://api.jquery.com/text/

    Code for the question below:

    $index = 1;
    while($row = $result->fetch_assoc()){
        print
        "<tr>".
            "<td id='numbers".$index."' class='col-md-4 text-center'>{$row["number"]}</td>".
            "<td class='col-md-1 text-center'>$row["names"]</td>".
        "</tr>";
        $index += 1;
    }
    
    评论

报告相同问题?

悬赏问题

  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭
  • ¥15 2020长安杯与连接网探
  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么