<input name="text" type="text" id="textid" onkeypress="handleKeyPress(event)">
function handleKeyPress(e){
var key=e.keyCode || e.which;
if (key === 13){ // Клавиша Enter
doSomething();
}
}
class Button {
constructor(name) {
this.name = name;
this.elem = document.createElement('button'), this.elem.textContent = this.name;
this.id = String.fromCharCode(Math.random() * (91 - 65) + 65) + Date.now();
}
onClick() {
console.log(this.name, this.id);
}
render(parent) {
parent.appendChild(this.elem);
this.elem.addEventListener('click', this.onClick.bind(this));
}
}
const b = new Button('Click me');
b.render(document.body);
b.elem.click();
const buttons = document.querySelectorAll('button');
buttons.forEach(el => el.textContent = el.name);
const buttons = [...document.querySelectorAll('button')].reduce((a, c, i) =>
(a['button' + i] = {name: c.name, id: c.id}, a), {});