Stack overflow at line 0

。_饼干妹妹 提交于 2019-12-05 03:53:07

Internet Explorer is firing the event propertychange whenever you use jQuery to addClass or removeClass. The problem code is here:

     var field = $(this);
        field.data("value", field.val());
        field.bind("propertychange keyup input paste", function(event){
            if(field.data("response") && (field.val() != field.data("value"))) {
                toggleFlag(field, "hide");
                if($.isArray(field.data('linked_fields'))) {
                    $.each(field.data('linked_fields'), function(key, value) {
                        toggleFlag(value, "hide");
                    });
                }
            }
      });

In your toggleFlag function you call jQuery's addClass and removeClass. That created the infinite recursion loop that led to the stack overflow.

If you take out the propertychange it works great on Internet Explorer as well as all other browsers.

Working example: http://jsfiddle.net/yuNXm/9/

The reason you were having this problem only on Internet Explorer is that onpropertychange is a proprietary event implemented by Microsoft for Internet Explorer. It is not implemented by other browsers.

Debugging stack overflows with IE6-8:

A good method you can use in the future to diagnose these types of stack overflows is to:

  1. Identify one of the functions involved with the infinite recursion loop. If you're stuck with IE6-8 with no debugging capability, then this entails placing alerts in various functions till you find an infinitely looping function.

  2. Place this line of code at the top of the function:

    alert(arguments.callee.caller.toString());

This alert will tell you which function is calling the infinitely looping function. Then by tracing back which functions are involved in the infinite recursion loop, you can isolate the parts of your code you need to closely examine for the cause of the infinite loop.

Of course if you have a modern web browser with proper debugging tools, this isn't necessary--you would just step through the code.

On a side note, I feel your pain. Part of my job also involves coding JavaScript for corporate clients where IE6-8 is often the browser imposed by their IT Dept. No debug tools, just alerts and comments; not even a line number to work with when you're troubleshooting stack overflows.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!