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 python的qt5界面
  • ¥15 无线电能传输系统MATLAB仿真问题
  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100