简体   繁体   中英

IE6 Jquery Namespace problem

The following code works in all browsers apart from IE6...

var mylib =
{
    selectStyle :
    {
        init : function()
        {
            $('#select-box1').jqTransform({imgPath:'jqtransformplugin/img/'});
        }
    }
}

<script type="text/javascript">
mylib.selectStyle.init();
</script>

The error states 'mylib' is undefined

Can someone please help otherwise I will have to spend alot of time redoing a lot more code than this.

Many thanks, C

Add a semicolon at the end of the definition of mylib.

var mylib = { ... };

When declaring anything in var something = ...; always add a semicolon at the end.

Thank you IE, you are so wonderful, reminding us to put semicolons. (Sarcasm? maybe...)

Edit: The semicolon is not a recommendation, IE considers it an error if you don't put it after closing curly brackets, so if you declare a function in a var, put the semicolon too.

var myFunc = function(){ .... }; .

But if you declare a function in the namespace, you don't need to add the semicolon.

function doSomething(){ ... } <-- no semicolon.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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