1,js中使用php变量

    1. <?php $userid = 1;?> //此处userid是调取过来的,我是为了让大家明白给它赋值了;
    1. <a id="denglu">我要投诉</a>
    1. <script type="text/javascript">
    2. var btn = document.getElementById('denglu');
    3. var userid = <?=$userid?>; //此处为取得上方php值
    4. btn.onclick = function () {
    5. if (userid > 0){
    6. window.location.href='index.php?g=Member&m=Tousu&a=index';
    7. }else {
    8. alert('请先登录');
    9. }
    10. }
    11. </script>

    2,php中使用js

    1. <?php
    2. $a="aaa";
    3. echo "
    4. <script>
    5. alert('你好');
    6. location.href='mail.php?username=".$a."';
    7. </script>
    8. ";
    9. ?>