<html>
<head>
<meta charset="utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<title>计算</title>
<meta name="viewport" content="width=device-width, initial-scale=1" />
</head>
<body>
<script>
function student(serialNumber, name, sex, birthday, score) {
this.serialNumber = serialNumber
this.name = name
this.sex = sex
this.birthday = birthday
this.score = score
}
student.prototype.getAge = function() {
var birthday = new Date(this.birthday.replace(/-/g, "\/"))
var d = new Date()
var age =
d.getFullYear() -
birthday.getFullYear() -
(d.getMonth() < birthday.getMonth() ||
(d.getMonth() == birthday.getMonth() &&
d.getDate() < birthday.getDate())
? 1
: 0)
return age
}
student.prototype.study = function() {
this.score++
}
var obj = new student(1, '张三', '男', '1990-01-01', 65)
console.log('入参:', 1, '张三', '男', '1990-01-01', 65)
console.log('年龄:', obj.getAge())
obj.study()
console.log('学习:', obj.score)
obj.study()
console.log('学习:', obj.score)
var obj2 = new student(2, '王五', '女', '1970-01-01', 85)
console.log('入参:', 2, '王五', '女', '1970-01-01', 85)
console.log('年龄:', obj2.getAge())
obj2.study()
console.log('学习:', obj2.score)
obj2.study()
console.log('学习:', obj2.score)
obj2.study()
console.log('学习:', obj2.score)
</script>
</body>
</html>
html5很多人把页面结构写在js中是提高页面的加载速度。JS写在HTML中是JS的代码不是太多,单独一个JS文件反而影响了页面的加载速度。因此html5很多人把页面结构写在js中是提高页面的加载速度。
HTML5是构建Web内容的一种语言描述方式。HTML5是互联网的下一代标准。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)