简体   繁体   English

IE7中的对象预期错误-函数范围出现问题?

[英]Object Expected error in IE7 - problem with function scope?

I'm having what I hope is a simple-to-fix issue. 我遇到了一个希望解决的简单问题。

Basically, I've got one block of javascript containing the function, and then I'm trying to call it from another block of javascript (within a jQuery $(document).ready function). 基本上,我有一个包含该函数的javascript块,然后尝试从另一个javascript块(在jQuery $(document).ready函数中)调用它。 Whilst it works fine on Firefox, I get an 'Object Expected' error in IE7. 尽管它在Firefox上可以正常工作,但在IE7中却收到“对象预期”错误。 It's probably something to do with scope, but I'm not sure what to fix. 这可能与范围有关,但我不确定要解决什么。 Firebug doesn't seem to give any light on the subject. Firebug似乎对此问题没有任何启示。

So, here's my function: 所以,这是我的功能:

    <script type="text/javascript">
    //<![CDATA[
    function onsite_validate(){
            $("#tsp_onsite_form").validate({
                errorClass: "form_error",   
                errorElement: "em",
                errorPlacement: function(error, element) {
                    error.prependTo( element.parent("label") );
                },
                highlight: function(element, errorClass) {
                     $(element).addClass(errorClass);
                },
                unhighlight: function(element, errorClass) {
                    $(element).removeClass(errorClass);
                },
                rules: { 
                    fault_found: "required"
                }, 
                messages: {
                    fault_found: "was a fault found?"
                },
                submitHandler: function(form) {
                    $.blockUI();
                    form.submit();

                } //ends submit handler     

            });
        }
//]]>
</script>

and after this, I have the following: 然后,我有以下内容:

<script type="text/javascript">
//<![CDATA[
$(document).ready(function() {
        onsite_validate();
});
//]]>
</script>

The 'Object Expected' error throws on calling onsite_validate(); 调用onsite_validate()时引发“预期对象”错误;

I'm sure I'm making a fundamental mistake - just can't seem to spot it! 我确定我犯了一个根本性的错误-似乎无法发现它!

Many thanks 非常感谢

What type of object is error in errorPlacement ? errorPlacement error是什么类型的对象? Not entirely sure if it's passed as an instance of jQuery, but if not, you might need to work around that. 不能完全确定它是否作为jQuery实例传递,但如果不是,则可能需要解决。

Edit: just realized you said it works in non-IE. 编辑:刚意识到您说它在非IE中有效。 I remember having this error in IE7 only, and having to patch the jQuery source to handle it. 我记得只有在IE7中存在此错误,并且必须修补jQuery源才能进行处理。 What version of jQuery are you using, and are you hosting it yourself or using something like GoogleAPIs? 您使用的是哪个版本的jQuery,是您自己托管还是使用诸如GoogleAPI之类的代码? Also, can you provide the exact error (file, line, etc)? 另外,您能否提供确切的错误(文件,行等)?

在IIS中

Click on your website[LHS]=>Authentication[**Features View on RHS**]=>Enable only Anonymous authentication other should be disabled and click on edit, set Specific user to **IUSR** instead of [IUSR_Servernname] and No password is required

I've had this error when trying to load the same javascript file twice (in nested templates). 尝试两次(在嵌套模板中)加载相同的javascript文件时遇到此错误。 It was difficult to identify because the problem occurred elsewhere in the flow. 由于该问题发生在流程中的其他位置,因此很难识别。

What I'm saying is that the error isn't necessarily with that function or even that code block. 我的意思是错误不一定与该函数甚至该代码块有关。

Sounds like you have a null reference in one of those callback functions. 听起来您在这些回调函数之一中具有空引用。

Just for debugging, you might try checking each of the objects against null and throwing an alert as needed to figure out which object isn't getting set. 仅出于调试目的,您可以尝试检查每个对象是否为null并根据需要抛出警报以找出未设置哪个对象。

For example, check these objects: 例如,检查以下对象:
element.parent element.parent
error 错误
$(element) $(元素)

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

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