H5 input新增type属性color颜色拾取器

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/CodingNoob/article/details/82108015

这里写图片描述

<!DOCTYPE html>
<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>color拾取器</title>
</head>
<body>
  <input type="color" id="color">
</body>
<script>
  document.querySelector("#color").onchange = function () {
    document.getElementById('color').click(); // 必须添加触发click事件否则不能通过点击确定按钮触发更改颜色
    document.body.style.background = this.value;
  }
</script>
</html>

猜你喜欢

转载自blog.csdn.net/CodingNoob/article/details/82108015
今日推荐