使用如下
代码
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
</head>
<style>
</style>
<body>
</body>
</html>
<script src="jquery.min.js"></script>
<script>
class demo {
constructor(id) {
this.domInit(id);
this.a = $('#'+id);
}
domInit(id) {
$('body').append('<div id="'+id+'" style="width: 100px;height: 100px;background-color: #009688;"></div>')
}
alert() {
alert('我是alert')
}
show() {
this.a.show();
}
hide() {
this.a.hide()
}
changeColor() {
let c1 = Math.floor(Math.random() * 255)
let c2 = Math.floor(Math.random() * 255)
let c3 = Math.floor(Math.random() * 255)
this.a.css('background-color', 'rgb(' + c1 + ',' + c2 + ',' + c3 + ')')
}
}
</script>