dongshuo1257 2013-08-29 18:15
浏览 39
已采纳

onclick重定向到存储在php变量中的url

I have the following table:

foreach ($forwards as $data):
    ?>

    <tr style="cursor: pointer" class="main_row">

        <td><?php echo $data['Offer']['id']; ?> </td>
        <td><?php echo $data['Offer']['name'];?> </td>
        <td><?php echo round($data['Stat']['ltr'],2)."%"; ?></td>
        <td><?php echo round($data['Stat']['cpc'],2)."%"; ?></td>
        <td><?php echo $data['Category']['name']?></td>
        <td><?php echo $data['Country']['name'] ?></td>
    </tr>
    <?php
     endforeach; ?>

now the idea is that when ever you click one of the main_row it should redirect to a new url. the problem is that the url contains an id for instance the url could look like www.example.com/details/2 where 2 is the id.

This id is like all of the other data stored in a php variable: $data['Offer']['id'];

Now my question how can i redirect using both php and javascript? is there a work around? .

Please do note that i am fully aware that php i server side and javascript is not. it is because of this i am asking this question.

  • 写回答

4条回答 默认 最新

  • duandao7704 2013-08-29 18:25
    关注

    You can get the ID from the first column in the row:

    $(".main_row").click(function() {
        var id = $(this).find("td:first-child").text();
        window.location.href = 'www.example.com/details/' + id;
    });
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

悬赏问题

  • ¥15 import arcpy出现importing _arcgisscripting 找不到相关程序
  • ¥15 onvif+openssl,vs2022编译openssl64
  • ¥15 iOS 自定义输入法-第三方输入法
  • ¥15 很想要一个很好的答案或提示
  • ¥15 扫描项目中发现AndroidOS.Agent、Android/SmsThief.LI!tr
  • ¥15 怀疑手机被监控,请问怎么解决和防止
  • ¥15 Qt下使用tcp获取数据的详细操作
  • ¥15 idea右下角设置编码是灰色的
  • ¥15 全志H618ROM新增分区
  • ¥15 在grasshopper里DrawViewportWires更改预览后,禁用电池仍然显示