作为一个前端开发者, 我现在主要遇到的问题是点击一个switch按钮会弹出确认框,确认是否更改,但是由于switch按钮设计的漏洞,我一旦点击或是用键盘触发这个按钮,switch样式就会改变,在不改变这个组件的情况下如何实现确认之后再更改样式?
时间: 2024-02-24 18:59:31 浏览: 83
Android开发实现Switch控件修改样式功能示例【附源码下载】
!\n");
return;
}
Choice *ch = &choices[*k];
printf("Enter student id: ");
scanf("%为了在确认之后再更改 Switch 组件的样式,可以采用以下步骤:
1. 在点击 Switch 组件时s", ch->id);
for (int i = 0; i < n; i++) {
if (strcmp(students[i,弹出确认框并暂停 Switch 组件的状态变化。
2. 当确认框的确认按钮被点击时,更新 Switch].id, ch->id) == 0) {
printf("Enter program code: ");
scanf("%s", ch->code);
组件的状态,并更改其样式。
3. 当确认框的取消按钮被点击时,恢复 Switch 组件的状态。
for (int j = 0; j < m; j++) {
if (strcmp(programs[j].code, ch->code以下是一个示例代码,用于实现在确认之后再更改 Switch 组件的样式:
```html
<div class) == 0) {
printf("Enter remark: ");
scanf("%s", ch->remark);
(*k)++;
return="switch-container">
<input type="checkbox" id="switch" class="switch">
<label for="switch" class="switch;
}
}
printf("Program not found!\n");
return;
}
}
printf("Student not found!\-label"></label>
</div>
```
```css
.switch-container {
position: relative;
display: inline-block;
width:n");
}
void browse_choices(const Choice *choices, int k) {
printf("ID\tCode\tRemark\n");
for (int 60px;
height: 34px;
margin: 10px;
}
.switch {
display: none;
}
.switch-label i = 0; i < k; i++) {
print_choice(&choices[i]);
}
}
void save_students(const Student *students {
position: absolute;
top: 0;
left: 0;
width: 60px;
height: 34px;
background-color: #ccc;
border-radius: 17px;
cursor: pointer;
transition: background-color , int n) {
FILE *fp = fopen("students.txt", "w");
if (fp == NULL) {
printf("0.2s;
}
.switch:checked + .switch-label {
background-color: #6bbd62;
}
.switch-label:before {
Cannot open file!\n");
return;
}
for (int i = 0; i < n; i++) {
fprintf content: "";
position: absolute;
top: 2px;
left: 2px;
width: 30px;
(fp, "%s %s %s %d %s %s\n", students[i].name, students[i].id, students[i]. height: 30px;
background-color: #fff;
border-radius: 50%;
transition: transform 0.2s;
}
.switch:checked + .switch-label:before {
transform: translateX(26px);
}
```
```javascript
var switchElschool, students[i].total_score, students[i].address, students[i].phone);
}
fclose(fp);
}
void save_program = document.getElementById("switch");
var switchLabelEl = document.querySelector(".switch-label");
var switchContainerEl = document.querySelector(".switch-container");
s(const Program *programs, int m) {
FILE *fp = fopen("programs.txt", "w");
if (fp == NULLswitchContainerEl.addEventListener("click", function(event) {
event.preventDefault();
event.stopPropagation();
switchEl.disabled = true; //) {
printf("Cannot open file!\n");
return;
}
for (int i = 0; i < m; 禁用 Switch 组件
var confirmResult = window.confirm("确认更改吗?");
if (confirmResult) { // 确认 i++) {
fprintf(fp, "%s %s %s %s %d\n", programs[i].code, programs[i].name,更改
switchEl.checked = !switchEl.checked; // 更新 Switch 组件的状态
switchLabelEl.style.backgroundColor = switchEl.checked ? "#6bbd62" : "#ccc"; // 更改 Switch 组件的样式
} else { // 取消更 programs[i].type, programs[i].college, programs[i].quota);
}
fclose(fp);
}
void save_choices(const Choice *改
switchEl.checked = !switchEl.checked; // 恢复 Switch 组件的状态
}
switchEl.disabled = falsechoices, int k) {
FILE *fp = fopen("choices.txt", "w");
if (fp == NULL) {
printf; // 启用 Switch 组件
});
```
通过上述代码,我们在 Switch 组件的外层容器上监听 `click`("Cannot open file!\n");
return;
}
for (int i = 0; i < k; i++) {
fprintf(fp, "%s %s %s\n", choices[i].id, choices[i].code, choices[i].remark);
}
事件,弹出确认框并暂停 Switch 组件的状态变化。当确认框的确认按钮被点击时,更新 Switch fclose(fp);
}
void load_students(Student *students, int *n) {
FILE *fp = fopen("students.txt", "r");
组件的状态,并更改其样式。当确认框的取消按钮被点击时,恢复 Switch 组件的状态。这样,就可以在确认之后再更改 Switch 组件的样式了。
阅读全文