2
我在IE7中弹出一个问题,只有当onChange
事件对于任何类型为VariationSelect
的选择框时,它将发出"Object doesn't support the property or method"
错误。因此,我已经收窄到以下几点:仅在IE7中使用jQuery问题
$(".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错误中的行/ char引用(当然毫无意义)不会改变。那么你是否看到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>
的快速和肮脏的方式做到这一点,因为我知道这个名字元素将始终有一个数字比索引大,就是抢从元素的名称,改变类似:
var index = $(this).attr('name');
index = index.replace('variation[','');
index = index.replace(']','');
index = (index*1)-1;
有没有更快/更好的方式来获得索引?
什么是财产或方法?你用调试器运行这个吗? – gilly3
我想我们需要查看'updateSelectedVariation'的代码。 – Shmiddty
在jQuery中使用attr函数时,它必须是您在线上运行的唯一函数。 (更改代码: $('。VariationSelect:eq('+(index + 1)+')')。append(data.options).attr('disabled','')。焦点(); : $('。VariationSelect:eq('+(index + 1)+')')。append(data.options); ('。VariationSelect:eq('+(index + 1)+')')。attr('disabled',''); $('。VariationSelect:eq('+(index + 1)+')')。focus(); 它现在在IE7中工作,并且它可以在其他所有浏览器中继续工作。我猜想我可以结合附加和聚焦功能,但是,呃,它工作。 –