<head>
<meta charset="utf-8">
<title>onclick的使用</title>
</head>
<body>
<input type="submit" onclick="window.alert('hello,js!')"/>
</body>
<head>
<meta charset="utf-8">
<title>多个alert</title>
</head>
<body>
<input type="submit" onclick="alert('hello');
alert('javascript');alert('java');"/>
</body>
这里的onclick是事件句柄,不叫作事件,click才是事件
一般以标签属性的方式存在
第二种嵌入script代码的方式 用script标签,从上而下依次去进行,可以在任意地位置
<script>
alert("hello js")
</script>
<!DOCTYPE html>
<!-- alert有阻挡界面加载的作用,script是自上而下依次去加载的,可以在代码块的任意位置 -->
<script>
alert("hello js!")
</script>
<html>
<head>
<meta charset="utf-8">
<title>script代码块的执行位置</title>
</head>
<body>
<script>
alert("hello js!!!!!")
</script>
<input type="submit"/>
</body>
</html>
<script>
alert("hello js!!!!!!!!!!!!!!!!!")
</script>
第三种引入外部的js代码:
(不可以在引入脚本的代码块儿里面在写代码,不可以简化标签)
window.alert("hello,js")
alert("hi,js!!")
<head>
<meta charset="utf-8">
<title>第三种方式引入外部的js文件</title>
</head>
<body>
<script type="text/javascript" src="js/js-01.js">
//这里面不可以再写代码块儿了 并且下面的/script>不可以简化
</script>
</body>
js的变量必须要提前去声明,但是后续调用的时候,跟着python差不多
js函数方法的调用:
<head>
<meta charset="utf-8">
<title>js函数的调用方法</title>
</head>
<body>
<script>
add=function(a,b){
alert(a+b);
}
</script>
<script>
function mul(a,b){
alert(a*b)
}
</script>
<input type="submit" onclick="add(1,2)"/>
<input type="submit" onclick="mul(1,2)"/>
</body>
NaN表示一个具体存在的值,not a nummber
js里面并没有方法的重载
后面的函数会将之前的函数覆盖掉
一个变量在声明的时候如果没有使用var关键字,不管是在哪里声明的,都是全局变量
变量虽然没有数据类型,但是后面的数值是有数据类型的
Es6表示的是规范,Es6之前的数据类型有6种,Es6之后的数据类型有7种
只声明,没有去赋值,就是undefined
NaN不是一个数字,但是也是Number类型
Infinity无穷也是Number类型
运算结果本来是个数字,运算之后不是数字的,类型就是Nan
在除数为零的时候结果为无穷大
这里的Math.ceil表示的是向上取整
Js中的boolean类型永远都只有两个值,true和false
在布尔类型当中 boolean可以将布尔类型转化成布尔类型
可以自动调用boolean ()将非布尔类型转换为布尔
规律:有就转换成true 没有转换成false
Null里面只有一个数值null
type of null表示的是object
深入浅出JavaScript-老杜JavaScript基础教程全套完整版【JavaScript从入门到实战】_哔哩哔哩_bilibili
这里的是回顾
String
substr和substring的区别:
Object数据类型:
<script type="text/javascript">
/*
是所有类型的超类
Object java 里面还有hashcode toString
prototype属性可以自由拓展类的属性和方法
js当中如何定义类;
js当中定义类和定义函数是一样的
如果调用的时候使用了new就是类
*/
function student(){
alert("Student.....")
}
//当作普通的对象
student();
//当作类来调用
var stu = new student();
</script>
可以通过调用自定义的成员属性来获取数值
<body>
<script type="text/javascript">
function student(a,b,c){
this.age = a;
this.name = b;
this.school = c;
}
var stu = new student(10,"Whut",22)
alert(stu.age);
alert(stu.name);
alert(stu.school);
</script>
</body>
<script type="text/javascript">
function student(a,b,c){
this.age = a;
this.name = b;
this.school = c;
}
var stu = new student(10,"Whut",22)
/*
alert(stu.age);
alert(stu.name);
alert(stu.school);
*/
// 还有这样的方式
alert(stu["age"])
alert(stu["name"])
alert(stu["school"])
</script>
js的代码只可以在js的代码块里面来写
<script type="text/javascript">
function student(a,b){
this.a=a;
this.b=b;
this.add=function(){
return this.a;
}
}
student.prototype.mul = function(){
alert("hello js!");
return this.a;
}
var stu = new student(1,2);
stu.mul();
</script>
null和Nan以及undefined的区别:
null和undefined是可以等同的
两个等号表示的是数值相等,三个等号表示的数据类型和数值都是相等的