-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
15 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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(); | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters