var childNode = document.createElement('p'); childNode.innerHTML = '这里是提示信息〜〜'; //childNode.setAttribute('class', 'alerts'); //childNode.setAttribute('onclick', 'this.style.display = "none"'); childNode.className = 'alerts'; childNode.onclick = function () { this.style.display = 'none'; } document.getElementsByTagName('body')[0].appendChild(childNode);