我正在使用以下代码:
<script type="text/javascript"> <?php $ctnme = $_SERVER['REQUEST_URI']; $cnme = explode("/",$ctnme); echo $cname = $cnme[1]; ?> var spge = <?php echo $cname; ?> ; alert(spge); </script>
该值不警报。怎么了
实质上:
<?php //somewhere set a value $var = "a value"; ?> <script> // then echo it into the js/html stream // and assign to a js variable spge = '<?php echo $var ;?>'; // then alert(spge); </script>