2020-11-07

学习JavaScript 需要了解的前期知识

1.JavaScript的三种书写方式(行内,内嵌,外部)

1.行内式js,直接写到元素内部
<input  type="button" value="点击" onlick="alert('行内式js')">
2.内嵌式
<script> alert('内嵌式'</script> 
3.外部js文件(用外部文件script标签中间不要写代码)
<script src="script.js"></script>

2.注释
// 单行注释 快捷键 ctrl+/
/* */ 多行注释 快捷键 ctrl+shift+/

3.输入与输出语句

//警示框
alert('这是一个警示框,浏览器会弹出来'//输入框
prompt('浏览器弹出输入框,用户可以输入值')
//控制台
console.log('f12,console')

4.变量variable

  1. 通俗我们可以把变量理解为一个盒子,盒子是用来放东西的。变量就是用来放数据的,我们通过变量得到数据,也可以用来修改数据。
  2. 变量的本质可以说是,程序在内存中申请的一块用来存放数据的空间。
  3. 声明变量 与赋值
//var用来声明变量的关键字
  var  age;
  age=3;
  //初始化变量
  var age =3
  1. 赋值注意

    更新变量以最后一次为准、
    声明多个变量用英文逗号隔开,
    变量只声明不赋值 ----undefined,
    不声明不赋值 ----直接报错,
    不声明直接赋值----可以用,

  2. 命名规范
    使用任意多个英文字母、数字、下划线(_)或者美元符($)组成。
    不能使用JavaScript关键词与JavaScript保留字。
    严格区分大小写。
    不能以数字开头。
    驼峰命名法 myName

5数据类型

js中的数据类型是通过值来确定的。而且js是动态语言,数据类型可以变。

简单数据类型
number 数字型
Boolean 布尔型
string 字符型
undefined 只声明无赋值
null 空值
数据类型之间的转换
转换为字符
转换为数字
转换为布尔

6.if else

7.if else if

8.switch

9.for循环

10.while 与 do while

11.函数

12.常用互动方法

  • document.write
  • alert
  • confirm
  • prompt
  • window.open
  • window.close

dom

  • document.getElementById(“id”)
  • Object.innerHTML
  • Object.style.property=new style
  • Object.style.display = value
  • object.className = classname

慕课网JavaScript入门篇,黑马程序员JavaScript零基础入门

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
可以使用 Java 中的 LocalDateTime 类来处理时间。 首先,我们需要将给定的时间段转换为 LocalDateTime 对象: ```java LocalDateTime start = LocalDateTime.of(2020, 11, 20, 0, 0, 0); LocalDateTime end = LocalDateTime.of(2021, 10, 9, 23, 59, 59); ``` 这里将结束时间设置为 23:59:59 是因为我们想要包含该日期的所有时间。 接下来,我们可以使用一个循环来遍历时间段中的每一天,并获取该天的开始时间和结束时间: ```java LocalDateTime current = start; while (!current.isAfter(end)) { LocalDateTime dayStart = current.withHour(0).withMinute(0).withSecond(0).withNano(0); LocalDateTime dayEnd = current.withHour(23).withMinute(59).withSecond(59).withNano(999999999); System.out.println("Day " + current.toLocalDate() + " starts at " + dayStart + " and ends at " + dayEnd); current = current.plusDays(1); } ``` 这里,我们使用 `withHour`、`withMinute`、`withSecond` 和 `withNano` 方法来设置每天的开始时间和结束时间。然后,我们可以使用 `plusDays` 方法来增加 `current` 对象的日期,以便遍历整个时间段。 完整代码如下: ```java import java.time.LocalDateTime; public class Main { public static void main(String[] args) { LocalDateTime start = LocalDateTime.of(2020, 11, 20, 0, 0, 0); LocalDateTime end = LocalDateTime.of(2021, 10, 9, 23, 59, 59); LocalDateTime current = start; while (!current.isAfter(end)) { LocalDateTime dayStart = current.withHour(0).withMinute(0).withSecond(0).withNano(0); LocalDateTime dayEnd = current.withHour(23).withMinute(59).withSecond(59).withNano(999999999); System.out.println("Day " + current.toLocalDate() + " starts at " + dayStart + " and ends at " + dayEnd); current = current.plusDays(1); } } } ``` 输出结果如下: ``` Day 2020-11-20 starts at 2020-11-20T00:00 and ends at 2020-11-20T23:59:59.999999999 Day 2020-11-21 starts at 2020-11-21T00:00 and ends at 2020-11-21T23:59:59.999999999 Day 2020-11-22 starts at 2020-11-22T00:00 and ends at 2020-11-22T23:59:59.999999999 ... Day 2021-10-07 starts at 2021-10-07T00:00 and ends at 2021-10-07T23:59:59.999999999 Day 2021-10-08 starts at 2021-10-08T00:00 and ends at 2021-10-08T23:59:59.999999999 Day 2021-10-09 starts at 2021-10-09T00:00 and ends at 2021-10-09T23:59:59.999999999 ```
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值