Skip to content

Commit

Permalink
增加了第二个按钮的随机颜色
Browse files Browse the repository at this point in the history
  • Loading branch information
goodhyz committed Nov 16, 2023
1 parent f9edf79 commit 293b2aa
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 17 deletions.
25 changes: 11 additions & 14 deletions func.js
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();
}

7 changes: 4 additions & 3 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -102,10 +102,10 @@ <h3>添加几个按钮/开关 并在后面添加随机数字 ----李岳烁 23.11
<button onclick="addone()" class="nes-btn is-primary" value="一个按钮" name="button1"
style="width: 160px;">+1</button>
<input type="textbox" id="num1" value=><br>
<button onclick="changecolor()" class="nes-btn is-success" value="另一个按钮" name="button2"
<button onclick="setBottonRandomColor()" class="nes-btn is-success" value="另一个按钮" name="button2"
style="width: 160px;">改变颜色</button>
<input type="textbox" id="num2" value=><br>
<button onclick="changeSign()"class="nes-btn is-error" value="最后一个按钮" name="button3" style="width: 160px;">切换正负</button>
<button class="nes-btn is-error" value="最后一个按钮" name="button3" style="width: 160px;">切换正负</button>
<input type="textbox" id="num3" value=>
<script>
var num1 = document.getElementById("num1");
Expand All @@ -120,7 +120,8 @@ <h4 style="color: green;">[已解决] 完美 而且真的写了随机数 </h4>
<h3>创建js文件并给按钮添加点击效果 要求点击后 随机数字加一 ----胡昱之 23.11.15</h3>
<h4 style="color: green;">[已解决] 奈斯 相当不错 </h4>

<h3>在js中给按钮添加点击效果 要求点击后 随机数字改变颜色 ---- 胡昱之 23.11.15</h3>
<h3>在js中给按钮添加点击效果 要求点击后 随机数字改变颜色 ---- 胡昱之、彭欣玥23.11.16</h3>

<h3>在js中给开关添加点击效果 要求点击后 随机数字切换正负 ----xxx 23.11.xx</h3>
<h3 id="hyperlink">将这个需求变为一个超链接 要求这个链接可以在js中随意配置 默认链接为原神的官网 ----曹雪宸小 & xxx 23.11.15</h3>
<script>
Expand Down

0 comments on commit 293b2aa

Please sign in to comment.