一段有用的JS

(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

一段有用的JS

上一篇:momentjs 常用功能文章


下一篇:第 1 题:HTML 和 HTML5 有什么区别?