SOURCE

console 命令行工具 X clear

                    
>
console
var mainFunc = function() {
  var screen = document.getElementsByClassName('screen-inner')[0];
  var numBtns = document.getElementsByClassName('btn-number');
  for (var i = 0; i < numBtns.length; i++) {
    numBtns[i].onclick = function() {
      var num = this.getAttribute('value');
      screen.firstChild.nodeValue += num;
    };
  }

  var opraBtns = document.getElementsByClassName('btn-operator');
  var opras = ['+', '-', '*', '/', '.'];
  for (i = 0; i < opraBtns.length; i++) {
    opraBtns[i].onclick = function() {
      var screenValue = screen.firstChild.nodeValue;
      if (screenValue && opras.indexOf(screenValue[screenValue.length - 1]) === -1) {
        screen.firstChild.nodeValue += this.getAttribute('value');
      }
    };
  }

  var signBtn = document.getElementById('btn-sign');
  signBtn.onclick = function() {
    var screenValue = screen.firstChild.nodeValue;
    if (screenValue[screenValue.length - 1] === '-') {
      screen.firstChild.nodeValue = screenValue.slice(0, -1) + '+';
    } else if (screenValue[screenValue.length - 1] === '+') {
      screen.firstChild.nodeValue = screenValue.slice(0, -1) + '-';
    } else {
      screen.firstChild.nodeValue += '-';
    }
  };

  var clearBtn = document.getElementById('btn-clr');
  clearBtn.onclick = function() {
    screen.firstChild.nodeValue = '';
  };

  var delBtn = document.getElementById('btn-del');
  delBtn.onclick = function() {
    var screenValue = screen.firstChild.nodeValue;
    screen.firstChild.nodeValue = screenValue.slice(0, -1);
  };

  var equalBtn = document.getElementById('btn-equal');
  equalBtn.onclick = function() {
    var screenValue = screen.firstChild.nodeValue;
    var ans = eval(screenValue);
    screen.firstChild.nodeValue = ans;
  };
};

window.onload = mainFunc;
<div class="container row">
  <div class="screen col-12">
    <div class="screen-inner">
    </div>
  </div>
  <button class="col-3 btn-control" id="btn-clr" value="clr">
    C
  </button>
  <button class="col-3 btn-operator" value="/">
    /
  </button>
  <button class="col-3 btn-operator" value="*">
    *
  </button>
  <button class="col-3 btn-control" id="btn-del" value="del">
    <</button>
      <button class="col-3 btn-number" value="7">
        7
      </button>
      <button class="col-3 btn-number" value="8">
        8
      </button>
      <button class="col-3 btn-number" value="9">
        9
      </button>
      <button class="col-3 btn-operator" value="-">
        -
      </button>
      <button class="col-3 btn-number" value="4">
        4
      </button>
      <button class="col-3 btn-number" value="5">
        5
      </button>
      <button class="col-3 btn-number" value="6">
        6
      </button>
      <button class="col-3 btn-operator" value="+">
        +
      </button>
      <button class="col-3 btn-number" value="1">
        1
      </button>
      <button class="col-3 btn-number" value="2">
        2
      </button>
      <button class="col-3 btn-number" value="3">
        3
      </button>
      <button class="col-3 btn-equal" id="btn-equal" value="=">
        =
      </button>
      <button class="col-3 btn-operator btn-bottom" id="btn-sign" value="±">
        ±
      </button>
      <button class="col-3 btn-number btn-bottom" value="0">
        0
      </button>
      <button class="col-3 btn-operator btn-bottom" value=".">
        .
      </button>
</div>
.container {
  width: 480px;
  height: 320px;
  border: solid 1px #FFCCCC;
  border-radius: 1%;
  padding: 4px;
  box-shadow: 0 0 20px #FFCCCC;
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
}

.screen {
  height: 70px;
  font-size: 32px;
  line-height: 70px;
  background: #FFF;
}

.screen-inner {
  float: right;
}

button {
  height: 50px;
  border: none;
  outline: none;
  font-size: 1.2em;
}

.btn-number {
  background: #FFF;
  color: #6c6c6c;
}

.btn-number:hover,
.btn-control:hover,
.btn-operator:hover {
  background: #FFCCCC;
  color: #FFF;
}

.btn-control {
  background: #f7f7f7;
  color: #FF9999;
}

.btn-equal {
  height: 100px;
  background: #FFCCCC;
  color: #FFF;
}

.btn-equal:hover {
  background: #FFF;
  color: #FFCCCC;
}

.btn-bottom {
  position: absolute;
  bottom: 50px;
}

.btn-operator {
  color: #FF9999;
  background: #FFF;
}

@media (max-width: 768px) {
  body {
    height: 100%;
  }
  .container {
    width: 100%;
    height: 100%;
    padding: 0;
  }
  .screen {
    height: 20%;
    position: relative;
  }
  .screen-inner {
    position: absolute;
    top: 50%;
    right: 0;
    transform: translate(0, -50%);
  }
  .btn-control,
  .btn-number,
  .btn-operator {
    height: 16%;
  }
  .btn-equal {
    height: 32%;
  }
  .btn-bottom {
    bottom: 16%;
  }
}

.row::after,
.row::before {
  content: '';
  display: table;
}

.row::after {
  clear: both;
}

.col-1,
.col-2,
.col-3,
.col-4,
.col-5,
.col-6,
.col-7,
.col-8,
.col-9,
.col-10,
.col-11,
.col-12 {
  box-sizing: border-box;
  display: block;
  position: relative;
  float: left;
  min-height: 1px;
}

.col-1 {
  width: 8.333%;
}

.col-2 {
  width: 16.667%;
}

.col-3 {
  width: 25%;
}

.col-4 {
  width: 33.333%;
}

.col-5 {
  width: 41.667%;
}

.col-6 {
  width: 50%;
}

.col-7 {
  width: 58.333%;
}

.col-8 {
  width: 66.667%;
}

.col-9 {
  width: 75%;
}

.col-10 {
  width: 83.333%;
}

.col-11 {
  width: 91.667%;
}

.col-12 {
  width: 100%;
}