学习nodejs必会基础预备知识

Posted 勇敢*牛牛

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了学习nodejs必会基础预备知识相关的知识,希望对你有一定的参考价值。

学习nodejs必会基础预备知识


01-javascript 创建 JSON 对象 .html

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>JavaScript 创建 JSON 对象 </title>
</head>

<body>
    <h2>JavaScript 创建 JSON 对象</h2>
    <p>
        网站名称: <span id="jname"></span><br />
        网站地址: <span id="jurl"></span><br />
        网站 slogan: <span id="jslogan"></span><br />
    </p>

</body>
<script>
    var JSONobjet = 
        "name": '菜鸟教程',
        "url": 'www.runoob.com',
        "slogan": "学的不仅仅是梦想,更是梦想!"
    ;
    document.getElementById('jname').innerHTML = JSONobjet.name;
    document.getElementById('jurl').innerHTML = JSONobjet.url
    document.getElementById('jslogan').innerHTML = JSONobjet.slogan
</script>

</html>

02-JSON数据的数组访问.html

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <h2>JavaScript 创建 JSON 对象</h2>
    <p>第一个网站名称: <span id="name1"></span></p>
    <p>第一个网站修改后的名称: <span id="name2"></span></p>

</body>
<script>
    var sites = [
         "name": "runoob", "url": "www.runoob.com" ,
         "name": "google", "url": "www.google.com" ,
         "name": "微博", "url": "www.weibo.com" 
    ]
    document.getElementById('name1').innerHTML = sites[0].name;
    sites[0].name = '菜鸟教程';
    document.getElementById('name2').innerHTML = sites[0].name;
</script>

</html>

03-使用for in 循环访问对象.html

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>使用forin循环访问对象</title>
</head>

<body>
    <p>使用 for-in 来循环对象的属性:</p>
    <p id="demo"></p>

</body>
<script>
    var myobject = 
        "name": "runoob",
        "alexa": 10000,
        "site": null
    ;
    for (x in myobject) 
        document.getElementById("demo").innerHTML += x + "<br/>"
    
</script>

</html>

04-JSON嵌套对象.html

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>JSON嵌套对象</title>
</head>

<body>
    <p>访问 JSON 内嵌对象。</p>
    <p id="demo"></p>

</body>
<script>
    var myobject = 
        "name": "runoob",
        "alexa": 1000,
        "sites": 
            "site1": "www.bao.com",
            "site2": ".cwww.cum.cn",
            "site3": "c.runoob.com"
        
    
    // 选中的是sites里面的第一个键值
    document.getElementById("demo").innerHTML += myobject.sites.site1 + "<br/>";
    //和:“.” 的用法一样,也就是说值Wie对象的的键值对也可以通过[]来获取
    document.getElementById("demo").innerHTML += myobject.sites["site1"];
</script>

</html>

05-循环内嵌数组.html

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>循环内嵌数组</title>
</head>

<body>
    <p>循环内嵌数组:</p>
    <p id="demo"></p>

</body>
<script>
    var i, j, x = '';
    var obj = 
        "name": "网站",
        "num": 3,
        "sites": [
             "name": "Google", "info": ["android", "Google 搜索", "Google 翻译"] ,
             "name": "Runoob", "info": ["菜鸟教程", "菜鸟工具", "菜鸟微信"] ,
             "name": "Taobao", "info": ["淘宝", "网购"] 
        ]
    

    for (i in obj.sites) 
        // console.log(i);
        x += '<h1>' + obj.sites[i].name + '</h1>';
        // console.log(x);
        for (j in obj.sites[i].info) 
            x += obj.sites[i].info[j] + '<br/>';
        
    
    document.getElementById('demo').innerHTML = x;
</script>

</html>

06-使用 XMLHttpRequest 来获取JSON文件内容解析并显示.html

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>使用 XMLHttpRequest 来获取JSON文件内容解析并显示</title>
</head>

<body>
    <h2>使用XMLHttprequest来获取文件内容</h2>
    <p>文件内容是标准的酒json格式,可以使用JSON.parse方法将其转为JavaScript对象</p>
    <p id="demo"></p>
    <p>查看JSON文件数据<a href="myjsion.json" target="_blank">myjsion.json</a></p>
</body>
<script>
    var xmlhttp = new XMLHttpRequest();
    xmlhttp.onreadystatechange = function () 
        if (this.readyState == 4 && this.status == 200) 
            myobj = JSON.parse(this.responseText);
            document.getElementById('demo').innerHTML = myobj.name;
        
    ;
    xmlhttp.open('GET', "myjsion.json", true);
    xmlhttp.send();
</script>

</html>

07-JavaScript 对象转换为 JSON 字符串.html

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>JavaScript 对象转换为 JSON 字符串</title>
</head>

<body>
    <h2>将 JavaScript 对象转换为 JSON 字符串</h2>
    <p id="demo"></p>

</body>
<script>
    var obj =  "name": "菜鸟", "alexa": 10000, "site": "www.runnob.com" ;
    var myjson = JSON.stringify(obj);
    document.getElementById('demo').innerHTML = myjson;
</script>

</html>

08-函数的自调用球.html

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>函数的自调用球</title>
</head>

<body>
    请输入圆的半径:<input type="number" id="radius" name="radius">
    <select id="type" name="type">
        <option value="circu">周长</option>
        <option value="area">面积</option>
        <option value="volume">体积</option>
    </select>
    <input type="button" value=" 计  算 " id="btnCal">

</body>
<script>
    function getCircu(r) 
        return 2 * Math.PI * r;
    ;
    function getArea(r) 
        return Math.PI * Math.pow(r, 2);
    ;
    function getTiji(r) 
        return 4 / 3 * Math.PI * Math.pow(r, 3);
    ;
    document.getElementById('btnCal').onclick = function C++学习笔记—— 基础知识预备,以及“面向对象”的C++

C语言 输入半径 求圆的面积和周长

python编写圆的面积的程序

求用python输入圆的半径,计算圆的周长和面积,结果保留2位小数的代码

编写java代码:输入圆半径,输出周长和面积,要求采用符号常量

java scanner输入,控制台输出。输入圆的半径,计算圆的周长和面积