Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

改变颜色 #6

Merged
merged 1 commit into from
Nov 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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';
}
}