douquan2023 2016-12-26 04:26
浏览 48

将php变量分配给javascript变量

I want to assign a php variable to javascript variable.

<?php 
  $type =1;  
  $form = ' <script>                
             var jquery_type " <?php = $type;  ?>";
           </script>';            
?>

But in source page, it is showing like below,

var jquery_type " <?php = $type; ?>" ;

How can i get this php value ?

  • 写回答

4条回答 默认 最新

  • dongnan1989 2016-12-26 04:29
    关注

    within php code :

    $type = 1;  
    $form =   '<script>                
                var jquery_type =  "'.$type.'";
                alert(jquery_type);
            </script>';
    echo $form;
    


    If its js file.

    var jquery_type =  " <?php echo $type; ?>";
    
    评论

报告相同问题?