class Button {
constructor(name) {
this.target = 'bullseye';
this.name = name;
this.element = this.create();
}
create() {
var button_html = '<div>'+this.name+'</div>';
var button_element = $(button_html);
button_element[0].addEventListener('click', function(e) {
Button.yell('??????');
//Should be buttonA, or buttonB depending on which one was clicked. I have tried, (this) & (e), but to no success.
});
$('body').append(button_element);
return button_element;
}
static yell(element){
alert('You have hit the '+element.target);
}
}
let buttonA = new Button('Button A');
let buttonB = new Button('Button B');
https://jsfiddle.net/x4dsgp5b/1/
我觉得我在这里误解了一些非常基本的东西。将[可单击]按钮放置在类的主体上并与按钮A或按钮B(取决于单击哪个)进行交互的正确语法/逻辑是什么?
回首忆惘然
梵蒂冈之花
湖上湖
元芳怎么了
相关分类