简体   繁体   English

Chrome和Opera中的复选框切换

[英]Checkbox toggle in Chrome and Opera

Steps to reproduce the issue: 重现此问题的步骤:

  1. In your browser Settings select Continue where you/I left off under On startup . 在浏览器的SettingsOn startup Continue where you/I left off下选择Continue where you/I left off
  2. Navigate to the demo . 导航到演示
  3. Check the checkbox. 选中复选框。
  4. Edit the text. 编辑文字。
  5. Close your browser and reopen it. 关闭浏览器,然后重新打开。 Or duplicate/clone the tab. 或复制/克隆标签。

Now as you see the checkbox is checked, but the textarea isn't colored. 现在,如您所见,该复选框已选中,但文本区域未着色。
I tried it in the latest version of Chrome and Opera in Windows 10. I'm not sure about Safari, but it probably behaves the same way. 我在Windows 10的最新版本的Chrome和Opera中进行了尝试。我不确定Safari,但其行为可能与以前相同。

Questions: 问题:

  • Why does it happen? 为什么会发生?
  • What's a cross-browser solution? 什么是跨浏览器解决方案?

Try 尝试

window.onload = function() {
  document.getElementById('colorsToggle').onchange = function() {
    document.getElementById('textField').classList.toggle('tan');
  }
  document.getElementById('textField').classList.toggle(document.getElementById('colorsToggle').checked ? "tan" : "white");
};

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM