Skip to content

Commit

Permalink
Merge pull request #6 from hhhJB/main
Browse files Browse the repository at this point in the history
改变颜色 是不是忘记写名字和日期啦
  • Loading branch information
Faucet7 authored Nov 15, 2023
2 parents a118a76 + b883d37 commit ae7622a
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
2 changes: 1 addition & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ <h3>添加几个按钮/开关 并在后面添加随机数字 ----李岳烁 23.11
<button onclick="addone('num1')" class="nes-btn is-primary" value="一个按钮" name="button1"
style="width: 160px;">+1</button>
<input type="textbox" id="num1" value=><br>
<button class="nes-btn is-success" value="另一个按钮" name="button2" style="width: 160px;">改变颜色</button>
<button onclick="changecolor()" class="nes-btn is-success"value="另一个按钮" name="button2" style="width: 160px;">改变颜色</button>
<input type="textbox" id="num2" value=><br>
<button class="nes-btn is-error" value="最后一个按钮" name="button3" style="width: 160px;">切换正负</button>
<input type="textbox" id="num3" value=>
Expand Down
11 changes: 10 additions & 1 deletion test1.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,13 @@ function addone(id) {
var elem = document.getElementById(id);
var presnt = parseInt(elem.value) || 0;
elem.value = presnt + 1;
}
}
function changecolor() {
let button = document.getElementById("num2"); // access the button by id
let color = button.style.color;
if (color == "red") { // if button color is red change it green otherwise change it to red.
button.style.color = 'green';
} else {
button.style.color = 'red';
}
}

0 comments on commit ae7622a

Please sign in to comment.