仅在IE7中发出jQuery问题



我只有在IE7中弹出的问题,仅当onChange事件的任何选择框带有VariationSelect类时,它才会发出"Object doesn't support the property or method"错误。因此,我将其范围缩小到以下内容:

$(".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错误(当然是毫无意义的)不会改变。那么,您在该代码块中看到其他任何东西都不会接受吗?

编辑:更改选择框后,代码正在运行。选择框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>

做到这一点的快速而肮脏的方法,因为我知道名称元素将始终具有比索引大的数字,就是从元素中获取名称,而元素的名称则以以下方式更改为:

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

是否有更快/更好的方法来获取索引?

在jQuery中使用该atter时,它必须是您在行上运行的唯一功能。

要修复,我从:

更改了代码
    $('.VariationSelect:eq(' + (index + 1) + ')').append(data.options).attr('disabled', '').focus(); 

to:

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

现在它在IE7中起作用,并且它继续在所有其他浏览器中工作。我猜想我可能可以将附加功能结合起来,但是嗯,它正在起作用。

最新更新