<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
</head>
<body>
<!-- 用构造函数写 -->
<input type="button" value="看看" id="btn">
<p id="p1">Hello how are you</p >
<script>
var change = new change('btn', 'p1');
function change(b, p) {
this.btn = b;
this.p1 = p;
this.creatColor = function () {
return '#' + Math.floor(Math.random() * 0xffffff).toString(16);
}
this.creatSize = function () {
return Math.floor(Math.random() * 40 + 12);
}
Son.call(this);
function Son() {
var btn = document.getElementById(this.btn);
var p1 = document.getElementById(this.p1);
var aaa = this;
btn.onclick = function () {
p1.style.fontSize = aaa.creatSize() + 'px';
p1.style.color = aaa.creatColor();
}
}
}
</script>
</body>
</html>