1

選択したカテゴリに基づいてコンボ ボックスを変更するスクリプトを作成しました。問題は、スクリプトが Internet Explorer (バージョン 7 以降) 以外のすべてのブラウザーで機能することです。IE が object.innerhtml を好まないことを示すエラー メッセージが表示されません。これを解決するにはどうすればよいですか?

作業例: http://adcabinetsales.com/style-chooser.html

function ChangeCabinetCollection() {
    if (document.getElementById("cabinet_collection").value == "broughton") {
        // COPY VALUES
        var first = document.getElementById('broughton_styles');
        var options = first.innerHTML;
        var second = document.getElementById('cabinet_selector');

        // REPLACE VALUES
        second.innerHTML = options;

        // CHANGE CABINET IMAGE TO BE IN THE COLLECTION OF CHOICE
        changeDoor("cabinet_selector");
    } else if (document.getElementById("cabinet_collection").value == "specialty") {
        // COPY VALUES
        var first = document.getElementById('cabinet_style');
        var options = first.innerHTML;
        var second = document.getElementById('cabinet_selector');

        // REPLACE VALUES
        second.innerHTML = options;

        // CHANGE CABINET IMAGE TO BE IN THE COLLECTION OF CHOICE
        changeDoor("cabinet_selector");
    }
}

function ChangeGraniteCollection() {
    if (document.getElementById("granite_collection").value == "new_arrivals") {
        // COPY VALUES
        var first = document.getElementById('granite_new');
        var options = first.innerHTML;
        var second = document.getElementById('granite_selector');

        // REPLACE VALUES
        second.innerHTML = options;

        // CHANGE CABINET IMAGE TO BE IN THE COLLECTION OF CHOICE
        changeGranite("granite_selector");
    } else if (document.getElementById("granite_collection").value == "Specialty Styles") {
        // COPY VALUES
        var first = document.getElementById('specialty_granite_styles');
        var options = first.innerHTML;
        var second = document.getElementById('granite_selector');

        // REPLACE VALUES
        second.innerHTML = options;

        // CHANGE CABINET IMAGE TO BE IN THE COLLECTION OF CHOICE
        changeGranite("granite_selector");
    }
}
4

2 に答える 2

0

それ.innerHTMLは一般的ではありません。<select>問題を引き起こしている要素でそれを使用しています。この問題を解決するには、いくつかの方法があります。簡単な方法は、要素全体<select>をオプション リストと一緒に置き換えることです。つまり、HTML が次のようになっているとします。

<select name=whatever id=whatever>
  <option value=1>Hello
  <option value=2>World
</select>

次に、それを次のように変更できます。

<span class=select-wrapper>
  <select name=whatever id=whatever>
    <option value=1>Hello
    <option value=2>World
  </select>
</span>

.innerHTML次に、 の周りの<span>ラッパーの を置き換えるだけ<select>です。

<select>この問題を解決するもう 1 つの方法は、Option インスタンスの配列を作成し、要素の「オプション」プロパティを更新することです。

于 2013-07-07T14:13:44.197 に答える