好玩的小功能 console 改变字体颜色

256 阅读1分钟

效果:

代码:

 <html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>Document</title>
  <script src="https://cdn.bootcss.com/jquery/3.3.1/jquery.min.js"></script>
</head>

<body>
    <input type="text" id="inpBox"/>
</body>
<script type="text/javascript">
  var debounce = function (idle, action) {
    var last
    return function () {
      var ctx = this,
        args = arguments
      clearTimeout(last)
      last = setTimeout(function () {
        action.apply(ctx, args)
      }, idle)
    }
  }
  $("#inpBox").on('input propertychange', debounce(1000, function () {
          var val = $(this).val()
          console.log('%cval:'+val,'color:yellow;background:green;')
        }))

</script>

</html>