为什么IE8在运行这个jQuery时会冻结 - IE7,FF等都没问题?

时间:2010-08-12 17:18:47

标签: javascript jquery internet-explorer-8

我有一个带有选择字段的表单。根据选择,应显示可选的第二个字段(每个选项不同)以收集更多信息。我有一个我在jQuery中编写的脚本来执行此操作并将其快速转换为插件(目的是在以后将更多常用的表单相关代码添加到插件中 - 在此方面需要进行更改)。

无论如何,问题是这个代码在IE7,Firefox,Chrome,Opera等中运行良好。但是它一直导致在几台不同的计算机上安装IE8以完全冻结。它永远不会解冻,永远不会出错。鉴于缺乏任何可供调试的信息,我很困惑为什么会发生这种情况或者如何从这里进行故障排除。

HTML通常看起来像这样(剪辑)。

<!-- Controls Below -->
<li class="group-1 has-dependents">
   <label for="selSource">How did you hear about us?</label>
   <select id="selSource" name="selSource">
       <option value="0">Select One</option>
       <option class="group-referral" value="1">Referral</option>
       <option class="group-conference" value="4">Conference</option>
       <option class="group-other" value="7">Other</option>
   </select>
</li>

<!-- Controlled Above -->
<li id="itemSource" class="group-1 dependent">
   <!-- Opt 1 -->
   <label for="selSourceReferral" class="group-referral">Who gave the referral?</label>
   <select name="selSourceReferral" id="selSourceReferral" class="group-referral" disabled="disabled">
       <option value="0">Select One</option>
       <option value="101">....</option>
       <option value="102">....</option>
       <option value="103">....</option>
       <option value="999">....</option>
   </select>

   <!-- Opt 2 -->
   <label for="selSourceConference" class="group-conference">Which conference?</label>
   <select name="selSourceConference" id="selSourceConference" class="group-conference" disabled="disabled">
       <option value="0">Select One</option>
       <option value="101">....</option>
       <option value="102">....</option>
       <option value="103">....</option>
       <option value="999">....</option>
   </select>  

  <!-- Opt 3 -->
   <label for="txtSourceOther" class="group-other">Please Specify</label>
   <input type="text" name="txtSourceOther" id="Text1" class="group-other" disabled="disabled" />
   <input type="text" name="txtSourceSubOther" id="Text2" class="group-other" disabled="disabled" />
</li>

插件代码如下:

(function($){

    /* Show associated fields based on current selection */
    function show_dependents(_this, _event){
        var current = $('select option[value=' + $(_this).val() + ']').attr("class");
        if(current.length > 0){
            var temp = $(_this).closest('label, li, div, fieldset').attr("class").split(' ');
            for(var i = 0; i < temp.length; i++){
                if(temp[i].search("group-") >= 0){
                    temp = "." + temp[i] + "." + "dependent";
                    $(temp).find('label, input, select, li, div, fieldset').not('.' + current).fadeOut(function(){
                        $(temp).find('label, input, select, li, div, fieldset').not('.' + current).hide();
                    });
                    $(temp).find('.' + current).removeAttr('disabled').fadeIn();        
                }
            }
        }
    }

    $.fn.rlmforms = function(options){      
        return this.each(function(){

            $(this).bind('change.current', 
                function(e){
                    show_dependents(this, e);
                }
            );          
            $(this).trigger('change.current');
        }); // this.each()
    } // $.fn.rlmforms = function(options)

})(jQuery);

它被称为:

$('#selSource').rlmforms();

有什么想法吗?请注意,在加载页面时它不会冻结,而是在单击父选择字段时冻结。选项下拉,可以单击并突出显示一个选项。此时浏览器完全冻结,永不解冻。下拉列表甚至没有恢复,但是在点击突出显示的下拉列表中保持不变。

0 个答案:

没有答案
相关问题