From 293b2aa04a13405c5d8868c01592aed7dde15d12 Mon Sep 17 00:00:00 2001 From: goodhyz <202230444238@mail.scut.edu.cn> Date: Thu, 16 Nov 2023 21:20:50 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E4=BA=86=E7=AC=AC=E4=BA=8C?= =?UTF-8?q?=E4=B8=AA=E6=8C=89=E9=92=AE=E7=9A=84=E9=9A=8F=E6=9C=BA=E9=A2=9C?= =?UTF-8?q?=E8=89=B2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- func.js | 25 +++++++++++-------------- index.html | 7 ++++--- 2 files changed, 15 insertions(+), 17 deletions(-) diff --git a/func.js b/func.js index f1c1053..45df349 100644 --- a/func.js +++ b/func.js @@ -1,21 +1,18 @@ -function changecolor() { - var elem = document.getElementById("num2"); - var currentColor = window.getComputedStyle(elem).color; // 获取当前颜色 - var randomColor = getRandomColor(); // 生成一个随机颜色 - elem.style.color = randomColor; - } - + function addone() { var elem = document.getElementById("num1"); var present = parseInt(elem.value) || 0; elem.value = present + 1; } +function randomColor(){ + this.r = Math.floor(Math.random()*255); + this.g = Math.floor(Math.random()*255); + this.b = Math.floor(Math.random()*255); + this.color = 'rgba('+ this.r +','+ this.g +','+ this.b +',0.8)'; + return color; +} -function getRandomColor() { - var letters = '0123456789ABCDEF'; - var color = '#'; - for (var i = 0; i < 6; i++) { - color += letters[Math.floor(Math.random() * 16)]; - } - return color; +function setBottonRandomColor(){ + document.getElementById("num2").style.color = randomColor(); } + diff --git a/index.html b/index.html index 9ab3aeb..ef77a13 100644 --- a/index.html +++ b/index.html @@ -102,10 +102,10 @@