Мне нужна помощь для чего-то в javascript.
Идея в том, что я хочу создать новый элемент, используя метод createElement, и я хочу добавить свойство onclick к этому новому элементу, и я хочу, если щелкнуть по этому элементу.function.
Код, который я набрал, выглядит следующим образом:
HTML
<a href="javascript:popupWin.crWindow()">open</a>
Javascript
var popupWin = {
width: 640,
height: 480,
bg_colorBack: '#808080',
content: "<div style='margin:0 auto; text-align:center; width:640px; heihgt:480px; background-color:rgba(255,255,255,1.0); color:#000;'> Hello Wrold! </div>",
crWindow: function(){
var winElem = document.createElement('div');
winElem.id = 'flywin';
winElem.style.backgroundColor = this.bg_colorBack;
winElem.style.direction = 'rtl';
winElem.style.textAlign = 'center';
winElem.style.width = '100%';
winElem.style.height = '100%';
winElem.style.position = 'absolute';
winElem.style.top = '0';
winElem.style.left = '0';
winElem.style.opacity = '0.6';
winElem.style.filter = 'alpha(opacity=60)';
winElem.innerHTML = this.content;
winElem.onclick = this.closeWindow();
document.body.appendChild(winElem);
},
closeWindow: function(){
alert('hello');
}
}