繁体   English   中英

仅IE7中的jQuery Issue

[英]jQuery Issue in IE7 Only

我有一个问题仅在IE7中弹出,当任何带有VariationSelect类的选择框的onChange事件发生时,它将发出"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')的一段代码,因为我以前在IE7中使用removeAttr时也遇到了麻烦,但是即使我删除了这些行,错误仍然保持不变,并且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元素中总是会有一个比索引大一个数字,所以快速而又肮脏的方法是从发生以下变化的元素中获取名称:

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

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

在jQuery中使用attr函数时,它必须是您正在运行的唯一函数。

要修复,我将代码从:

    $('.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中使用,并且可以继续在其他所有浏览器中使用。 我猜我可能可以合并append和focus函数,但是,它正在工作。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM