<! DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, <meta HTTP-equiv =" x-UA-compatible "content=" IE =edge"> <title> </title> </head> <body> <button </button> </button type="button" id="btnpop"> </button type="button" id=" btnFrame "> Function createEl(fn) {var result; return function () { if (! result) { result = fn.apply(this, arguments); } return result; } } function createWindow() { var div = document.createElement("div"); Div. InnerHTML = 'I'm popover content '; div.style.display = 'none'; document.body.appendChild(div); return div; } function createIframe() { var iframe = document.createElement("iframe"); iframe.style.display = 'none'; document.body.appendChild(iframe); return iframe; } var fun01 = createEl(createWindow); var fun02 = createEl(createIframe); document.getElementById("btnpop").onclick = function () { var el = fun01(); el.style.display = 'block'; }; document.getElementById("btnframe").onclick = function () { var el = fun02(); el.style.display = 'block'; }; </script> </body> </html>Copy the code