首页 > 其他分享 >web前端 第五天总结

web前端 第五天总结

时间:2023-07-13 23:55:06浏览次数:61  
标签:web console log 前端 alert let 第五天 Document age

案例1:js初体验

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

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <button>点击我变成粉色</button>
    <script>
        const btn = document.querySelector('button')
        btn.addEventListener('click', () => {
            btn.style.backgroundColor = 'pink'

        })
    </script>
</body>

</html>

 

案例2:js的引入方式

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

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>




    <script>
        // 内部
        // prompt('请输入您的年龄:')
    </script>
    <!-- 外部 -->
    <script src="./03-外部js.js">
    </script>
</body>

</html>

 

外部js

prompt('年龄:')

 

案例3:输入输出语句

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

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>


    <script>
        // 输入语句
        // prompt('请输入您的密码:')
        // 打印到页面
        document.write('你们真是小天才')
        // 可以识别标签
        document.write('<strong>你们真是小天才</strong>')
        // 控制台输出语句
        console.log('我现在要在控制台输出')

    </script>
</body>

</html>

 

案例4:变量

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

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>


    <script>

        // 变量:盒子----存储数据的容器           数据本身不是变量
        //  变量的声明:
        // let 变量名           var  变量名
        // let age
        // //    变量赋值
        // age = prompt('请输入您的年龄:')

        // age = 33
        // console.log(age)


        // 变量的初始化
        // let uname = prompt('请输入您的用户名:')
        // console.log(uname)


        // 同时定义多个变量
        // let uname = 'zs', age = 21
        // console.log(uname, age)

        let age = prompt('请输入年龄:')
        document.write(age)

    </script>
</body>

</html>

 

案例5:变量命名规范

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

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>

    <script>
        // 变量命名规范:1、有效符号(大小写字母、数字、下划线、$)
        // 2、关键字、保留字不能用于变量命名
        // 3、不以数字开头
        // 4、尽量用有意义的变量名
        // 5、驼峰命名法       userName

    </script>

</body>

</html>

 

案例6:let和var的区别

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

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>



    <script>
        // var 可以多次声明同一变量  
        console.log(age)
        // var age
        let age
    </script>
</body>

</html>

 

案例7:const常量

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

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>

    <script>
        // 常量名大写   常量无法更改
        const PI = 3.14
        // PI = 4.456
        console.log(PI)
    </script>
</body>

</html>

 

案例8:数据类型

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

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        // js是弱数据类型语言    只有赋值之后,才知道是什么数据类型
        let uname = 21
        uname = 'gouxin'
        console.log(typeof (uname))
    </script>
</body>

</html>

 

案例9:基本数据类型--数字类型

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

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>


    <script>
        let a = 21.21312
        let b = 33
        console.log(a)
        console.log(a + 2)
        console.log(a + b)
        console.log(a - b)
        console.log(a * b)
        console.log(a / b)
        console.log(a % 2)

    </script>
</body>

</html>

 

案例10:字符串类型

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

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        // let uname1 = 'nnnsns'
        // console.log(typeof (uname1))
        // let uname2 = "nnnsns"
        // console.log(typeof (uname2))
        // let uname3 = "nnn'gouxin'sns"
        // console.log(typeof (uname3))
        // let uname4 = 'nnn"gouxin"sns'
        // console.log(typeof (uname4))


        // 字符串拼接用+

        let a = +prompt("请输入num1")
        let b = +prompt("请输入num2")
        // alert   警示框
        alert(a + b)


        // 模板字符串
        // let uname = prompt("请输入名字:")
        // let age = prompt("请输入年龄:")

        // document.write('你叫' + uname + ',今年' + age + '岁了')
        // document.write(`<strong>你叫${uname},今年${age}岁了</strong>`)

    </script>
</body>

</html>

 

案例11:布尔类型

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

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>

    <script>
        console.log(typeof (3 < 5))
        // undefinded  声明,未赋值
        // null   NaN   not a  number
        console.log(undefined + 1)
        console.log(null + 1)

    </script>
</body>

</html>

 

案例12:显示转换

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

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        let a = +prompt('num1')
        let b = +prompt('num2')

        console.log(Number(a) + Number(b))
        console.log(typeof (+a))

        let c = '200.9875px'
        console.log(parseInt(c))
        console.log(parseFloat(c))


    </script>
</body>

</html>

 

案例13:综合案例

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

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        h2 {
            text-align: center;
        }

        table {
            /* 合并相邻边框 */
            border-collapse: collapse;
            height: 80px;
            margin: 0 auto;
            text-align: center;
        }

        th {
            padding: 5px 30px;
        }

        table,
        th,
        td {
            border: 1px solid #000;
        }
    </style>
</head>

<body>
    <h2>订单确认</h2>



    <script>
        let price = +prompt('请输入单价:')
        let num = +prompt('请输入购买数量:')
        let address = prompt('请输入收货地址:')
        document.write(`
        <table>
        <thead>
            <tr>
                <th>
                    商品名称
                </th>
                <th>
                    商品价格
                </th>
                <th>
                    商品数量
                </th>
                <th>
                    总价
                </th>
                <th>
                    收货地址
                </th>
            </tr>
        </thead>
        <tr>
            <td>小米</td>
            <td>${price}</td>
            <td>${num}</td>
            <td>${price * num}</td>
            <td>${address}</td>


        </tr>
    </table>
        `)
    </script>


</body>

</html>

 

案例14:运算符

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

<head>
    <meta charset="UTF-8">
    <title>Document</title>
</head>

<body>
    <script>
        // =  赋值运算符
        // let a = 21
        // a = 33


        // a += 4 // a = a + 4
        // a *= 2   //a = a * 2     74
        //a -= 3    //a = a - 3
        // a /= 2     //a = a / 2      35.5
        // alert(a)



        // let b = a++  //先赋值,再自增
        // alert(b)
        // alert(a)  //36.5
        // b = ++a   //先自增,再赋值
        // alert(b)


        // 比较运算符  
        // >   <   >=   <=  ==   ===
        let num1 = 2
        let num2 = '2'
        alert(num1 == num2)
        alert(num1 === num2)
        // ==  (隐式转换)只比较数值,将字符串转换为数字类型后进行比较   ===   即比较数值,也比较类型


    </script>
</body>

</html>

 

案例15:逻辑运算符

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

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        // &&     ||       !
        //  alert(4 > 3 && 3 < 5)  //两真为真,一假则假
        // alert(4 < 3 || 3 < 5)  //一真则真   全假则假
        // alert(!true)
        alert(!(4 < 3))

    </script>
</body>

</html>

 

案例16:单分支语句

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

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        let age = 11
        // if(条件){
        //     执行的代码
        // }
        if (age < 18) {
            document.write('你是小弟弟,不要乱跑')
        }


    </script>
</body>

</html>

 

案例17:双分支语句

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

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>


    <script>
        let age = +prompt('请输入您的年龄:')
        if (age <= 18) {
            alert('你不要乱跑')
        } else {
            alert('恭喜你,成年了')
        }

    </script>
</body>

</html>

 

案例18:判断闰年

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

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        // year % 4 === 0 && year % 100 !== 0 || year % 400 === 0
        let year = +prompt('请输入年份:')
        if (year % 4 === 0 && year % 100 !== 0 || year % 400 === 0) {
            alert('闰年')
        } else {
            alert('平年')
        }
    </script>
</body>

</html>

 

案例19:多分支语句

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

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        let age = +prompt('age:')
        if (age < 18) {
            alert('你是未成年 学习吧')
        } else if (age <= 25) {
            alert('青春年华')
        } else if (age <= 40) {
            alert('好汉不提当年勇')
        } else {
            alert('男人四十一枝花')
        }
    </script>
</body>

</html>

 

案例20:三元运算符

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

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        let age = +prompt('请输入您的年龄:')
        // if (age <= 18) {
        //     alert('你不要乱跑')
        // } else {
        //     alert('恭喜你,成年了')
        // }

        // 判断条件?条件成立时执行的语句:条件不成立时执行的语句
        age <= 18 ? alert('你不要乱跑') : alert('恭喜你,成年了')
    </script>
</body>

</html>

 

案例21:求最大值

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

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        let a = +prompt('请输入num1:')
        let b = +prompt('请输入num2:')
        a > b ? alert(`最大值是:${a}`) : alert(`最大值是:${b}`)

    </script>
</body>

</html>

 

案例22:数字补零

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

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>

    <script>
        // alert(2 < '3')
        let a = prompt('num')
        a >= 10 ? alert(a) : alert(0 + a)

    </script>
</body>

</html>

 

案例23:switch

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

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        let num = +prompt('请输入今天星期几了:')
        switch (num) {
            case 1:
                alert('星期一')
                break
            case 2:
                alert('星期二了')
                break
            case 3:
                alert('星期三了')
                break
            case 4:
                alert('星期四了')
                break
            case 5:
                alert('星期五了')
                break
            case 6:
                alert('周末了')
                break
            case 7:
                alert('周末了')
                break
            default:
                alert('你是外星人吗')
        }
    </script>
</body>

</html>

 

案例24:while循环

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

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        // while   一定要有终止条件
        let i = 10
        // while (i > 11) {
        //     console.log('你是大聪明')
        //     i--
        // }


        do {
            console.log('你是大聪明')
            i--
        } while (i > 11)
    </script>
</body>

</html>

 

案例25:while练习(1-100累加和)

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

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        // 1~100累加和
        let i = 0
        let sum = 0
        while (i < 101) {
            sum += i
            i++
        }
        alert(sum)


    </script>
</body>

</html>

 

案例26:for循环

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

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        for (let i = 1; i <= 10; i++) {
            document.write(`你真是个大聪明<br>`)
        }
        //



    </script>
</body>

</html>

 

案例27:嵌套循环

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

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        span {
            display: inline-block;
            margin: 15px;
        }
    </style>
</head>

<body>
    <script>
        for (let i = 1; i < 8; i++) {
            console.log(`今天是第${i}天`)
            for (let j = 1; j < 11; j++) {
                console.log(`这是今天第${j}朵玫瑰花`)

            }
        }

        for (let i = 1; i < 10; i++) {
            for (let j = 1; j <= i; j++) {
                document.write(`<span>${j}*${i}=${i * j}</span>`);
            }
            document.write(`<br/>`)
        }


        for (let i = 1; i < 6; i++) {
            for (let j = 1; j <= i; j++) {
                document.write(`*`)
            }
            document.write(`<br/>`)
        }


    </script>
</body>

</html>

 

案例28:continue与break

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

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        for (let i = 1; i < 100; i++) {
            if (i === 50) {
                // break
                continue
            }
            console.log(i)
        }
        // break:跳出循环
        // continue:跳出本次循环
    </script>
</body>

</html>

 

案例29:循环加强

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

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        let arr = [1, 2, 3, 66, 4, 5]
        // for  in
        // for (let i in arr) {
        //     console.log(arr[i])
        // }
        // for   of
        for (let k of arr) {
            console.log(k)
        }

    </script>
</body>

</html>

 

案例30:数组

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

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        // let name1 = '俊杰'
        // 有序的数据序列
        //             0         1         2           3       4     5
        let arr = ['gouxin', 'huangzhong', 'jialuo', 'zhadanren', 12, true]
        // 数组的声明方式
        // arr[索引下标]
        alert(arr[5])

        // let arr2 = new Array()

        // 数组遍历
        // for (let i in arr) {
        //     console.log(arr[i])
        // }

        // 数组的操作   
        // 通过索引下标给对应元素重新赋值
        arr[1] = 'guanyu'
        console.log(arr instanceof Array)
        let arr2 = [1, 2, 3, 4]
        // concat合并数组
        arr3 = arr.concat(arr2)
        console.log(arr3)

        // 增 push   在数组末尾添加
        arr.push('姜加')


        // unshift  在数组首部添加元素

        arr.unshift('jiangjia')

        arr.shift()

        arr.pop()
        // splice(删除的起始位置,删除的个数)
        arr.splice(3, 1)
        // splice(删除的起始位置,0,要添加的元素)
        arr.splice(3, 0, 'jiangjia')
        console.log(arr)

        console.log(arr.join(' **'))
        console.log(arr.reverse())

        console.log(arr.slice(3))


    </script>
</body>

</html>

 

案例31:二维数组

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

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        let student = [['jiangjia', 31, 'sing'], ['xuchao', 21, 'dance']]

        // console.log(student[1][0])
        for (let i in student) {
            for (let j in student[i]) {
                console.log(student[i][j])
            }
        }


        // student.length   获取数组长度的
    </script>
</body>

</html>

 

标签:web,console,log,前端,alert,let,第五天,Document,age
From: https://www.cnblogs.com/wxy1787880204/p/17552526.html

相关文章

  • ASP.NET MVC4 WEB API跨域
    ASP.NETMVC4WEBAPI跨域web.config文件里加些东西即可 <system.webServer> <httpProtocol> <customHeaders> <addname="Access-Control-Allow-Origin"value="*"/> <addname="Access-Control-Allow-H......
  • 每日汇报 第三周第五天 JAVA集合
    今日所学:掌握Collection接口的常用方法;掌握Set接口的HashSet类和TreeSet类的异同点;掌握如何使用Iterator迭代器遍历集合中的元素;掌握List接口的两个重要方法get(intindex)和set(intindex,Objectobj);掌握Set接口的ArrayList类与LinkedList类的异同点;掌握Map接口的常用方法;......
  • 前端 手动全屏
    手动点击设置全屏/退出全屏html<divstyle="height:100%"v-if="isReloadData"><div@click="fullScreen()">{{isFullScreen?'退出全屏':'全屏展示'}}</div></div>jsexportdefault{data(......
  • H3C 模拟器 防火墙开启Web功能
    环境windows10,模拟器 HCL_V5.9.0防火墙 1在windows添加虚拟网卡我的电脑--管理--设备管理器--网络适配器(选择)--操作--(添加过时硬件)--进入向导-下一步--搜索并自动安装--选择网络适配器-2给虚拟网卡配置ip如上图中所示3在防火墙命令行配置<H3C>system-view[H3C......
  • defined in class path resource [de/codecentric/boot/admin/server/config/AdminSe
    搭建springbootadmin监控时出现的,经排查是版本过低,换个高版本的,顺利进入网页界面<dependency><groupId>de.codecentric</groupId><artifactId>spring-boot-admin-starter-server</artifactId><version>2.7.10</version......
  • CDN与前端技术
    本文分享自天翼云开发者社区《CDN与前端技术》,作者:张****亮CDN(ContentDeliveryNetwork)是一种广泛应用于网络加速和内容分发的技术。它通过在全球各地部署服务器节点,将静态资源如图片、CSS和JavaScript文件等缓存到离用户最近的节点上,从而提供更快速和可靠的内容交付。在前理、......
  • 【Azure App Service】Web Job 报错 UNC paths are not supported. Defaulting to Win
    问题描述PHP的WebJob,通过artisan来配置路径启动PHP任务,相关启动脚本如下:artisan_path="d:\\home\\site\\wwwroot";cd${artisan_path}echo"\n"pwdphpartisanschedule:run但是,在运行的时候遇见报错:[07/06/202301:57:31>0f21a2:INFO]/d/home/site/wwwroo......
  • 前端文件打开并且读取内容展示
    1.函数封装constonloadend1=(e:any,a:any)=>{ const{graph}=FlowGraphconstreader=newFileReader();constfileList=fileRef1.value.files//这个就是选中的文件流if(!fileList.length)returnreader.readAsText(fileList[0],"UTF-8");re......
  • 关于本地开发对接前端的解决思路
    场景1:假设局域网启动了一个禅道(管理项目的一个后台系统),ip为10.10.119.66:8081,我当然可以直接通过10.10.119.66:8081来访问到禅道了。但是我还想让别人都用个域名www.lidisam.cn:8081来访问禅道。解决步骤:1打开 C:\Windows\System32\drivers\etc\hosts,并编辑添加一行如下:......
  • 我开源了团队内部基于SpringBoot Web快速开发的API脚手架stater
    我们现在使用SpringBoot做Web开发已经比之前SprngMvc那一套强大很多了。但是用SpringBootWeb做API开发还是不够简洁有一些。每次WebAPI常用功能都需要重新写一遍。或者复制之前项目代码。于是我封装了这么一个抽出SpringBootWebAPI每个项目必备需要重复写的模块,和......