(function() { const container = document.createElement('div'); const console = document.createElement('pre'); const input = document.createElement('textarea'); const exec = document.createElement('button'); const log = (text) => { console.appendChild(document.createTextNode(text)); }; const clear = () => { console.textContent = ''; }; input.cols = 60; input.rows = 8; exec.textContent = 'exec'; exec.type = 'button'; exec.onclick = () => { eval(input.value); }; container.appendChild(input); container.appendChild(exec); container.appendChild(console); document.body.insertAdjacentElement('afterbegin', container); })();
点击button执行textarea框内的js