var Message =(function() { let message = "", time = 2000; let messageBox; let messageCen; let messageTitle; let type = ''; let redirectUrl = ''; function create() { // 创建默认弹窗--黑色提示框 if(type === 'default') { messageBox = document.createElement('div'); messageBox.className = 'message-box'; messageBox.id = 'messageBox'; document.body.appendChild(messageBox); } // 信息弹窗-带标题和关闭按钮 if(type === 'message' || type === 'messageLogin') { messageBox = document.createElement('div'); messageBox.className = 'message_body'; messageBox.id = 'messageBody'; var messageMain = document.createElement('div'); messageMain.className = 'message_main'; var messageHead = document.createElement('div'); messageHead.className = 'message_head'; var span = document.createElement('span'); span.innerText='信息'; var span1 = document.createElement('span'); span1.id = 'messageClose'; span1.onclick = close; messageHead.appendChild(span); messageHead.appendChild(span1); messageCen = document.createElement('div'); messageCen.className = 'message_cen'; var messageBtn = document.createElement('div'); messageBtn.className = 'message_btn'; var a = document.createElement('a'); a.id = "messageSub"; if(type === 'messageLogin') { a.innerText = '登录'; a.onclick = funSubmit; } if(type === 'message') { a.innerText = '好的'; a.onclick = close; } messageBtn.appendChild(a); messageMain.appendChild(messageHead); messageMain.appendChild(messageCen); messageMain.appendChild( messageBtn); messageBox.appendChild(messageMain); document.body.appendChild(messageBox); } // 提交成功弹窗 if(type === 'submit') { messageBox = document.createElement('div'); messageBox.className = 'message_body'; messageBox.id = 'messageBody'; var messageMain = document.createElement('div'); messageMain.className = 'messageSub_main'; var messageHead = document.createElement('div'); messageHead.className = 'message_head'; var span = document.createElement('span'); span.id = 'messageClose'; span.onclick = close; messageHead.appendChild(span); messageCen = document.createElement('div'); messageCen.className = 'message_cen'; var imgBox = document.createElement('div'); imgBox.className = 'message_img'; messageTitle = document.createElement('div'); messageTitle.className = 'message_title'; var messageSmallT = document.createElement('div'); messageSmallT.innerText = '我们将尽快与您联系'; messageCen.appendChild(imgBox); messageCen.appendChild(messageTitle); messageCen.appendChild(messageSmallT); messageBox.appendChild(messageMain); document.body.appendChild(messageBox); messageMain.appendChild(messageHead); messageMain.appendChild(messageCen); document.body.appendChild(messageBox); } } function show(message, Dtype='default', DredirectUrl='', time=2000) { type = Dtype; redirectUrl = DredirectUrl; if ((Dtype === 'default' && !document.getElementById('messageBox')) || Dtype !== 'default') { create(); } if(type === 'default') { messageBox.innerHTML = message; document.getElementById('messageBox').style.display = 'block'; // 设置2秒后自动隐藏弹窗 let timer = setTimeout(function() { clearTimeout(timer); message = ""; document.getElementById('messageBox').style.display = 'none'; document.getElementById('messageBox').remove(); }, time); } if(type === 'message' || type === 'messageLogin') { messageCen.innerHTML = message; document.getElementById('messageBody').style.display = 'block'; } if(type === 'submit') { messageTitle.innerHTML = message; document.getElementById('messageBody').style.display = 'block'; } } // 关闭方法 function close() { document.getElementById('messageBody').style.display = 'none'; document.getElementById('messageBody').remove(); } // 好的 function funSubmit() { document.getElementById('messageBody').style.display = 'none'; document.getElementById('messageBody').remove(); if(type === 'messageLogin') { window.locations.href = redirectUrl; } } return { show: show }; })()