2

"Object doesn't support the property or method"クラスonChangeVariationSelect. _ ということで以下に絞り込みました。

$(".VariationSelect").change(function() {
    // a bunch of irrelevant code
    // get the index of this select
    var index = $('.VariationSelect').index($(this)); //this is the line throwing the error in IE7
           //some code that returns a block of data in json formatting

});

attr('disabled', 'disabled')私の最初の考えは、 removeAttr も使用されたときに IE7 で以前に問題があったため、コードのセクションでしたが、それらの行を削除しても、エラーは同じままで、JS エラーの行/文字参照 (もちろん無意味です)は変わりません。では、IE7 が受け入れないコード ブロックが他にあるでしょうか。

編集:選択ボックスが変更された後にコードが実行されています。選択ボックスの HTML は次のようになります。

<div class="DetailRow">
<div class="Label">Some Label:</div>
<div class="Value">
    <select name="variation[aNumberStartingAtOneAndIncrementingUpwards]" class="VariationSelect" id="VariationSelect" style="width: 180px;">
        <option value="">-- Choose an option --</option>
        {A bunch of options for this choice loaded by PHP}
    </select>
</div>
</div>

name 要素には常にインデックスよりも 1 大きい数値が含まれていることがわかっているため、これを行う手っ取り早い方法は、次のように変更された要素から名前を取得することです。

    var index = $(this).attr('name');
index = index.replace('variation[','');
index = index.replace(']','');
index = (index*1)-1;

インデックスを取得するためのより高速でより良い方法はありますか?

4

1 に答える 1

1

その attr 関数を jQuery で使用する場合、その行で実行している唯一の関数でなければなりません。

修正するために、コードを次のように変更しました。

    $('.VariationSelect:eq(' + (index + 1) + ')').append(data.options).attr('disabled', '').focus(); 

に:

    $('.VariationSelect:eq(' + (index + 1) + ')').append(data.options); $('.VariationSelect:eq(' + (index + 1) + ')').attr('disabled', ''); 
    $('.VariationSelect:eq(' + (index + 1) + ')').focus();

また、IE7 で動作するようになり、他のすべてのブラウザーでも引き続き動作します。おそらく追加機能とフォーカス機能を組み合わせることができると思いますが、まあ、それは機能しています。

于 2013-11-27T21:27:42.880 に答える