IE11でのJavascriptの問題

user240141

私のアプリはIE9まで正常に動作していましたが、IE11にアップグレードすると動作を停止しました。これがサンプルのhtmlとjsです。

問題

最初の実行ですなわち。ロード時にそれはうまく機能します。しかし、PDAブランド選択すると、2番目のドロップダウンのすべてのオプションが空白になりました。

コンソールでInvalid Calling Object error、オブジェクトにスクリプトエラーがありましたclonedOptions

function dynamicSelect(id1, id2) {
  //alert("Everytime")
  // Browser and feature tests to see if there is enough W3C DOM support

  // Obtain references to both select boxes
  var sel1 = document.getElementById(id1);
  var sel2 = document.getElementById(id2);
  // Clone the dynamic select box
  var clone = sel2.cloneNode(true);
  // Obtain references to all cloned options
  var clonedOptions = clone.getElementsByTagName("option");
  // Onload init: call a generic function to display the related options in the dynamic select box
  refreshDynamicSelectOptions(sel1, sel2, clonedOptions);
  // Onchange of the main select box: call a generic function to display the related options in the dynamic select box

  sel1.onchange = function() {
    refreshDynamicSelectOptions(sel1, sel2, clonedOptions);
  };
}

function refreshDynamicSelectOptions(sel1, sel2, clonedOptions) {
  while (sel2.options.length) {
    sel2.remove(0);
  }

  //alert(sel1.options[sel1.selectedIndex].value)

  // Create regular expression objects for "select" and the value of the selected option of the main select box as class names
  var pattern1 = /( |^)(select)( |$)/;
  var pattern2 = new RegExp("( |^)(" + sel1.options[sel1.selectedIndex].value + ")( |$)");
  // Iterate through all cloned options
  //alert(clonedOptions.length);
  for (var i = 0; i < clonedOptions.length; i++) {
    // If the classname of a cloned option either equals "select" or equals the value of the selected option of the main select box

    if (clonedOptions[i].className.match(pattern1) || clonedOptions[i].className.match(pattern2)) {
      // Clone the option from the hidden option pool and append it to the dynamic select box
      //alert("Did match")

      sel2.appendChild(clonedOptions[i].cloneNode(true));
      //alert(sel2.options[1]);
    }
  }
}
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">

<head>
  <title>dynamic selectbox example</title>
  <script type="text/javascript" src="unobtrusivedynamicselect_ex5.js"></script>
</head>

<body>
  <form action="#">
    <div>
      <select id="pda-brand">
        <option value="select">Select PDA brand...</option>
        <option value="dell">Dell</option>
        <option value="hp">HP</option>
        <option value="palmone">PalmOne</option>
      </select>
      <select id="pda-type">
        <option class="select" value="select">Select PDA type...</option>
        <option class="dell" value="aximx30">Axim X30</option>
        <option class="dell" value="aximx50">Axim X50</option>
        <option class="hp" value="ipaqhx2750">iPAQ hx2750</option>
        <option class="hp" value="ipaqrx3715">iPAQ rx3715</option>
        <option class="hp" value="ipaqrz1710">iPAQ rz1710</option>
        <option class="palmone" value="tungstene2">Tungsten E2</option>
        <option class="palmone" value="tungstent5">Tungsten T5</option>
        <option class="palmone" value="zire72">Zire 72</option>
      </select>
      <script type="text/javascript">
        window.onload = function(e) {
          dynamicSelect("pda-brand", "pda-type");
        }
      </script>
    </div>
  </form>
</body>

</html>

問題のライン

以下の場所で、clonedOptionsの場合、Invalid CallingObjectエラーが発生します。

for (var i = 0; i < clonedOptions.length; i++) {
sabithpocker

IE-11で動作させることができました。自分で試してみてください。

私の理解によると、問題は次のとおりです。

var clone = sel2.cloneNode(true);
var clonedOptions = clone.getElementsByTagName("option");

clonedOptionsおそらくcloneタグ名持つの子への参照ですoption

  sel1.onchange = function() {
    refreshDynamicSelectOptions(sel1, sel2, clonedOptions);
  };

この関数には、への参照がありますが、への参照はありclonedOptionsませんcloneだから、cloneおそらくそれを維持する理由を見つけることができなかったIEとしてゴミとして収集されます。clonedOptions存在しないコレクションへの参照を保持します。

あなたはあなた自身の方法で修正することができます、私はclone代わりにただ通過しています、clonedOptionsそしてそれは私のために働きますIE11

function dynamicSelect(id1, id2) {
  //alert("Everytime")
  // Browser and feature tests to see if there is enough W3C DOM support

  // Obtain references to both select boxes
  var sel1 = document.getElementById(id1);
  var sel2 = document.getElementById(id2);
  // Clone the dynamic select box      // Obtain references to all cloned options
  var clone = sel2.cloneNode(true);
  // Onload init: call a generic function to display the related options in the dynamic select box
  refreshDynamicSelectOptions(sel1, sel2, clone);
  // Onchange of the main select box: call a generic function to display the related options in the dynamic select box

  sel1.onchange = function() {
    refreshDynamicSelectOptions(sel1, sel2, clone);
  };
}

function refreshDynamicSelectOptions(sel1, sel2, clone) {
  var clonedOptions = clone.getElementsByTagName("option");
  while (sel2.options.length) {
    sel2.remove(0);
  }

  //alert(sel1.options[sel1.selectedIndex].value)

  // Create regular expression objects for "select" and the value of the selected option of the main select box as class names
  var pattern1 = /( |^)(select)( |$)/;
  var pattern2 = new RegExp("( |^)(" + sel1.options[sel1.selectedIndex].value + ")( |$)");
  // Iterate through all cloned options
  //alert(clonedOptions.length);
  for (var i = 0; i < clonedOptions.length; i++) {
    // If the classname of a cloned option either equals "select" or equals the value of the selected option of the main select box

    if (clonedOptions[i].className.match(pattern1) || clonedOptions[i].className.match(pattern2)) {
      // Clone the option from the hidden option pool and append it to the dynamic select box
      //alert("Did match")

      sel2.appendChild(clonedOptions[i].cloneNode(true));
      //alert(sel2.options[1]);
    }
  }
}
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">

<head>
  <title>dynamic selectbox example</title>
  <script type="text/javascript" src="unobtrusivedynamicselect_ex5.js"></script>
</head>

<body>
  <form action="#">
    <div>
      <select id="pda-brand">
        <option value="select">Select PDA brand...</option>
        <option value="dell">Dell</option>
        <option value="hp">HP</option>
        <option value="palmone">PalmOne</option>
      </select>
      <select id="pda-type">
        <option class="select" value="select">Select PDA type...</option>
        <option class="dell" value="aximx30">Axim X30</option>
        <option class="dell" value="aximx50">Axim X50</option>
        <option class="hp" value="ipaqhx2750">iPAQ hx2750</option>
        <option class="hp" value="ipaqrx3715">iPAQ rx3715</option>
        <option class="hp" value="ipaqrz1710">iPAQ rz1710</option>
        <option class="palmone" value="tungstene2">Tungsten E2</option>
        <option class="palmone" value="tungstent5">Tungsten T5</option>
        <option class="palmone" value="zire72">Zire 72</option>
      </select>
      <script type="text/javascript">
        window.onload = function(e) {
          dynamicSelect("pda-brand", "pda-type");
        }
      </script>
    </div>
  </form>
</body>

</html>

この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。

侵害の場合は、連絡してください[email protected]

編集
0

コメントを追加

0

関連記事

分類Dev

IE11でのSVGの問題

分類Dev

IE11でJavaScriptの問題の安定ソートを作成する

分類Dev

IE11でのFlexboxの最大高さの問題

分類Dev

<input type = "file"> IE11ブラウザでの配置の問題

分類Dev

IE11でのBootstrap4 Flexboxmy-autoの問題

分類Dev

IE11でのPDFレンダリングの問題

分類Dev

<img> IE11でsrcを更新する際のちらつきの問題

分類Dev

IE11エディターでのコピー&ペーストの問題

分類Dev

アンカータグIE11の問題の内部のTextarea

分類Dev

私のサイトで問題を引き起こしているIE11

分類Dev

IE11開発ツールの問題-window.onloadの例外

分類Dev

IE11 Windows 7kb4021558以降の印刷の問題

分類Dev

IE11の画像のCSS問題センターと「最大幅」

分類Dev

IE11のフッターの問題

分類Dev

IE11のCSSブラウザ固有の問題

分類Dev

線形グラデーションIE11空白の問題

分類Dev

uuidv4.js正規表現の問題-IE11

分類Dev

ローカルホストを開くIE11の問題

分類Dev

埋め込みPDFに関するIE11の問題

分類Dev

IE 11Ajaxの問題

分類Dev

Twitter Bootstrap3を使用したサイトでのIE11ナビゲーションの問題

分類Dev

IE11フレックスボックスの列の高さの問題

分類Dev

IE11でAngular4アプリケーションの実行に関する問題

分類Dev

IE11のSVGnaturalWidth

分類Dev

ネストされたshowModalDialogに関するie11の問題

分類Dev

Vue Js:スコープスロットとIE11の問題

分類Dev

IE11の背景画像と境界線半径に関する奇妙な問題

分類Dev

IE11のJQueryappend()のJavaScript代替

分類Dev

IE11およびChromeでのJavaScript`this.closest`の使用

Related 関連記事

ホットタグ

アーカイブ