html_js之demo

a.js

 var errorString = "Please input a positive integer.";
 var arr = ["A", "B", "C", "D"];

 function count() {
     max = arr.length; //max, 全局变量
     document.getElementById("num").innerHTML = arr[parseInt(max * Math.random())];
 }

 function message(info) {
     alert(info);
 }

 function start() {
     timeId = setInterval("count();", 100);
 }

 function stop() {
     clearInterval(timeId);
 }

 function hiddenP () {
     //$("p").hide();
     var p = $("p");
     var h1 = $("h1");
     var p0 = p[0];
     if (p0.hidden == true)
         p0.hidden = false;
     else
         p0.hidden = true;
 }

testJs.html

<html>

<head>
    <title>random number</title>
    <script type="text/javascript" src="a.js"></script>
    <script type="text/javascript" src="D:/html/jquery/jquery-3.2.1.min.js"></script>
</head>

<body>
    <form>
        <input type="button" style='font-size:40px' value="Start" οnclick="start()">
        <input type="button" style='font-size:40px' value="Stop" οnclick="stop();">
    </form>
    <br>    
    <font color="blue" style='font-size:150px' id="num"></font>
    <br>
    <script>
        //message("html js分离");

    </script>
    <script type="text/javascript">
        $(document).ready(function() {
            /*$("button").click(
                function () {
                    //$("p").hide();
                    var p = $("p");
                    var h1 = $("h1");
                    var p0 = p[0];
                    if (p0.hidden == true)
                        p0.hidden = false;
                    else
                        p0.hidden = true;
                }
            );*/

            $("button").click(
                function aa() {
                   //hideP();//OK
                    hiddenP();//也OK,看来$这种在Js中的确也OK
                }
            );

            function hideP() {
                //$("p").hide();
                var p = $("p");
                var h1 = $("h1");
                var p0 = p[0];
                if (p0.hidden == true)
                    p0.hidden = false;
                else
                    p0.hidden = true;
            }   

        });

    </script>

    <div>
        <h2>This is a heading</h2>
        <p>This is a paragraph.</p>
        <p>This is another paragraph.</p>
        <h1>我是h1标签</h1>
        <button id="button1" type="button">Click me</button>
        <button id="button2" type="button">Click me</button>
    </div>

</body>

</html>



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值