LoginSignup
0
0

More than 3 years have passed since last update.

IE11では、チェックボックスのindeterminateプロパティが変化したときにonchangeイベントは発動しない

Posted at

JavaScriptを使うと、チェックボックスの中間状態を表すのに、indeteminateプロパティを使えます。
以下のHTMLをブラウザで表示すると、チェックボックスとボタンが表示されます。ボタンを押すと、チェックボックスが中間状態になります。

<meta charset="utf-8">
<input type="checkbox" id="test" onchange="showAlert()">
<input type="button" onclick="toIndeterminate()" value="チェックを中間状態にする">
<script>
  let checkbox = document.getElementById("test");

  let showAlert = function(){window.alert("alert")};
  let toIndeterminate = function(){checkbox.indeterminate = true};
</script>

ところがどうやらIEでは、チェックを中間状態にしてから、チェックボックスをクリックしても、onchangeイベントは発生しないようです。

仕方ないので、onclickにすることで対応しました。

<meta charset="utf-8">
<input type="checkbox" id="test" onclick="showAlert()">
<input type="button" onclick="toIndeterminate()" value="チェックを中間状態にする">
<script>
  let checkbox = document.getElementById("test");

  let showAlert = function(){window.alert("alert")};
  let toIndeterminate = function(){checkbox.indeterminate = true};
</script>
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0