Blogger Information
Blog 37
fans 0
comment 1
visits 29835
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
js变量、语句、表达式例子练习一遍-2019-10-22
H先生
Original
629 people have browsed it

    1、把js变量、语句、表达式例子练习一遍
    2、函数定义及调用、匿名函数练习一遍



<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>js变量</title>
</head>
<body>
<h1>JS变量</h1>
<p id="demo"></p>

<script>
    var price1 = 1;
    var price2 = 2;
    var price3 = 3;
    var total = price1 + price2 + price3;
  //  document.getElementById("demo").innerHTML = "总计:" + total;
    document.getElementById('demo').innerHTML = '总计:' + total;
</script>


<hr>
<h1>JS语句</h1>
<p id="demo1"></p>
<script>
    var name= "我是谁?";
    document.getElementById('demo1').innerHTML = name;
</script>
<hr>

<h2>JavaScript 函数是通过 function 关键词来定义的</h2>

<h2>调用</h2>
<p id="demo2"></p>
<script>
    var x = sum(4,2);

    function sum(a,b) {
        return a * b;
    }
    document.getElementById('demo2').innerHTML = x;
</script>

<hr>

<h3>匿名调用:没有实际名字的函数</h3>
<p id="demo3"></p>
<script>
    (function () {
        console.log('你好');
    })();
</script>


<hr>

<h5>JavaScript 弹窗</h5>

<button onclick="myFunction()">试一试</button>
<p id="demo4"></p>

<script>
    function  myFunction(){
        var text;
        if (alert("Press a button!")){
            text = "您点击了确定";
        } else {
            text = "您点击了取消按钮";
        }
        document.getElementById("demo4").innerHTML = text;
    }
</script>


</body>
</html>




QQ截图20191022192511.png











Correction status:qualified

Teacher's comments:以后, 可以在控制台中直接进行练习
Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!
All comments Speak rationally on civilized internet, please comply with News Comment Service Agreement
0 comments
Author's latest blog post