douzhong4222 2015-12-27 18:55
浏览 136
已采纳

单击功能,Window.location

currently, I am trying to set the URL of my website base on what the user click. The website is coding in html and php and this is the code I am trying to use to set the Url. However it seems that windows.location doesn't recognize php code. is there any other way to do this?

    <script>
        $(document).ready(function(){                         
    $("#HELP").click(function(){
   window.location='hotels.php?Category=<?php $cat ?>&Pic=<?php $img ?>';
            });
        });
    </script> 
  • 写回答

2条回答 默认 最新

  • dongsisui7562 2015-12-27 18:59
    关注

    Try this:

    <script>
     $(document).ready(function(){                             
    
      $("#HELP").click(function(){
        var url = 'hotels.php?Category=<?=$cat?>&Pic=<?=$img?>';
        window.location= url;
         });
      });
    </script> 
    

    What change: Echo php veriables in url

    But its not a good practice to use php code in client side you can create global veriables in java script.

    Or if your requirement is like that than you can also use a hidden value for url in html and than get value in your jQuery code as like that:

    <input type="hidden" id="url" value="<?=hotels.php?Category=<?=$cat?>&Pic=<?=$img?>" name="url">
    
    <script> 
    $(document).ready(function(){ $("#HELP").click(function(){ 
    var url = $('#url').val(); 
    window.location= url; 
    }); 
    }); 
    </script> 
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 急matlab编程仿真二阶震荡系统
  • ¥20 TEC-9的数据通路实验
  • ¥15 ue5 .3之前好好的现在只要是激活关卡就会崩溃
  • ¥50 MATLAB实现圆柱体容器内球形颗粒堆积
  • ¥15 python如何将动态的多个子列表,拼接后进行集合的交集
  • ¥20 vitis-ai量化基于pytorch框架下的yolov5模型
  • ¥15 如何实现H5在QQ平台上的二次分享卡片效果?
  • ¥15 python爬取bilibili校园招聘网站
  • ¥30 求解达问题(有红包)
  • ¥15 请解包一个pak文件