【发布时间】:2019-02-25 03:01:58
【问题描述】:
<div class="target">
</div>
<script>
class Shape {
constructor (id, x, y) {
this.id = id
this.x = x
this.y = y
this.display()
}
display() {
return
`
<div class="square">
<button class="square-button"></button>
</div>
`
}
}
var square = new Shape(0, 5, 5);
$('.target').html(square.display());
</script>
我想为将通过每个 Shape 实例生成的按钮添加一个事件侦听器。我该怎么做呢?
【问题讨论】:
标签: javascript html javascript-objects addeventlistener