I have a strange conflict in my code.
I have a function that called from body onload
:
var someGlobalVar=new SpecialType();
function OnBodyLoad()
{
someGlobalVar.Bind();
}
But when I include jQuery 1.4.2 in my project I get an error that someGlobalVar is undefined. Why is the global variable undefined now, and what ways are there to f开发者_高级运维ix it?
Unless you need to use <body onload='OnBodyLoad()'>
anymore, you can change thise to use jQuery's document.ready
(and move it to an external file!) like this:
var someGlobalVar=new SpecialType();
$(OnBodyLoad);
//or..
$(function() {
//other stuff..
OnBodyLoad();
});
//or...
$(document).ready(function() {
//other stuff..
OnBodyLoad();
});
Why don't you use jQuery's load event?
$(window).load(function() {
functiontoexecute();
});
It is simple, and it is easy.
Just a side note.
// DOM Ready
$(document).ready(function() {});
// When the page has completely loaded
<body onload="someFunction()">
Perhaps jQuery interferes with SpecialType
and so the call to new SpecialType();
results in the variable someGlobalVar being undefined
.
Try using the console to check for any warnings, and try to instantiate a SpecialType object manually. This should give you some insight.
精彩评论