• 6.PHP与JavaScript交互


    PHPJS交互

    JS年闰年判断(body里直接引用JS)


    <form name="form1" method="post" action="">
        <span class="style2">Jian Ce Run Nian:</span>
        <select name="year">
            <option value="2000">2000</option>
            <option value="2008">2008</option>
            <option value="2009">2009</option>
        </select>
        <input type="submit" name="Submit" value="Jian Ce" οnclick="check()">
    </form>

    <script language="javascript">
        function check(){
            var y1=form1.year.value;
            if(((y1 % == 0) && (y1 % 100 != 0)) || y1 % 400 == 0){
                alert(y1+"Nian Shi Run Nian");
            }else{
                alert(y1+"Nian Bu Shi Run Nian");
            }
        }
    </script>

    <?PHP
        echo "lalala";
    ?>

     


    SWITCH

    <script language="javascript">
        function check(books){
            switch (books) {
                case "1":
                    alert("11111");
                    break;
                case "2":
                    alert("22222");
                    break;
                case "3":
                    alert("33333");
                    break;
                case "4":
                    alert("44444");
                    break;
                case "5":
                    alert("55555");
                    break;
            }
        }
    </script>

    <body>
        <form name="form1" method="post" action="">
            <span class="style2">Ni Zui Xi Huan De Tu Shu Lei Bie:</span>
            <input name="book" type="radio" value="1" οnclick="check(this.value)">1
            <input name="book" type="radio" value="2" οnclick="check(this.value)">2
            <input name="book" type="radio" value="3" οnclick="check(this.value)">3
            <input name="book" type="radio" value="4 οnclick="check(this.value)">4
            <input name="book" type="radio" value="5" οnclick="check(this.value)">5
        </form>
    </body>

     

    While

    <script language="JavaScript" type="text/javascript">
        var i = 3;
        while(i > 0){
            document.write("-"+i);
            i --;
        }
    </script>


    For

    <script language="JavaScript">
        for(var i = ;i < 20 ;i ++){
            if(i > 10){
                break;
            }
            document.write(i+"-");
        }
    </script>

     

    JavaScript常用事件

     

     

    HTML嵌入JS

    <html>
        <head>
            <title>JS</title>
        </head>
        <body>
         <script language="JavaScript">
              alert("lalala");
         </script>
        </body>
    </html>

     


    PHP中添加JS文件

    <script src="j.js" language="JavaScript"></script>
    <?php

    ?>

     

    处理浏览器是否支持JS问题

    <html>
        <head>
            <title>Pan Duan Shi Fou Zhi Chi JS</title>
        </head>

        <body>
            <script language="JavaScript">
                <!--
                document.write("Nin De Liu Lan Qi Zhi Chi JS");
                -->
            </script>
            <noscript>
                Nin De Liu Lan Qi Bu Zhi Chi JS
            </noscript>
        </body>
    </html>

     

    JS事件


    <table width="761" height="20" border="0" cellpadding="0" cellspacing="0">
        <tr>
            <td width="75" align="center"><a href="#" onMouseMove="LL('1')">111</a></td>
            <td width="75" align="center"><a href="#" onMouseMove="LL('2')">222</a></td>
            <td width="75" align="center"><a href="#" onMouseMove="LL('3')">333</a></td>
        </tr>
    </table>

    <script language="JavaScript">
        function LL(V){
            switch (V){
                case "1":
                    document.write("111");
                    break;
                case "2":
                    document.write("222");
                    break;
                case "3":
                    document.write("444");
                    break;
                default:
                    alert("444");
            }
        }
    </script>

     

    PHP时间

    <?PHP
        $time1 = strtotime(date("Y-m-d H:i:s"));
        $time2 = strtotime("2017-2-24 17:10:00");
        $time3 = strtotime("2017-2-23");
        $sub1 = ceil(($time2-$time1));
        $sub2 = ceil(($time3-$time1));
        echo "<font color='red'> $sub1</font>";
        echo "<p>";
        echo "<font color='red'> $sub2</font>";
    ?>

     

     

  • 相关阅读:
    LeetCode 123 Best Time to Buy and Sell Stock III
    直接选择排序算法汇总
    zoom:1是什么意思
    怎么去掉织梦网站首页带的index.html/index.php
    wamp apache无法启动的解决方法
    提交到svn服务器时,一直缓冲不,
    桌面上图标都不见了怎么办听语音
    如何清除网上浏览痕迹?清除缓存
    TortoiseSVN文件夹及文件图标不显示解决方法
    快捷键
  • 原文地址:https://www.cnblogs.com/csnd/p/12062057.html
Copyright © 2020-2023  润新知