Как изменить состояние текста с помощью флажка [дубликат] ⇐ CSS
-
Anonymous
Как изменить состояние текста с помощью флажка [дубликат]
I am using a checkbox and styles to create a toggle switch. Currently, I need it to display the initial state as "off" when the page loads, and after clicking, it should change to "on". Similarly, when turned off, it should return to the previous position.
In addition, the on/off values should have different colors, so appropriate classes should be provided for them.
Below is an example of my code, I would appreciate any recommendations.
function ch_mode() { var toggle_state = document.getElementById('myCheck'); var check = document.getElementById('s_mode'); var another = document.getElementById('from'); var on = "on"; var off = "off"; if (toggle_state.checked) { another.innerText = on; } else { another.innerText = "OFF"; } } mode: OFF
Источник: https://stackoverflow.com/questions/781 ... g-checkbox
I am using a checkbox and styles to create a toggle switch. Currently, I need it to display the initial state as "off" when the page loads, and after clicking, it should change to "on". Similarly, when turned off, it should return to the previous position.
In addition, the on/off values should have different colors, so appropriate classes should be provided for them.
Below is an example of my code, I would appreciate any recommendations.
function ch_mode() { var toggle_state = document.getElementById('myCheck'); var check = document.getElementById('s_mode'); var another = document.getElementById('from'); var on = "on"; var off = "off"; if (toggle_state.checked) { another.innerText = on; } else { another.innerText = "OFF"; } } mode: OFF
Источник: https://stackoverflow.com/questions/781 ... g-checkbox
Мобильная версия