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中工作,並且它可以在其他所有瀏覽器中繼續工作。我猜想我可以結合附加和聚焦功能,但是,呃,它工作。 –