javascript文档准备firefox(jQuery) [英] javascript Document ready firefox (jQuery)

查看:207
本文介绍了javascript文档准备firefox(jQuery)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在FireFox中,我在这个body的最后有这个jQuery:

$ $ $ $(document).ready(function() {
$ .getScript('LiveMapsJavascriptProvider.aspx?type = reference& value = 6',init);
});

头文件中有很多js文件需要全部加载才能工作。所以我把我的电话放在一个document.ready事件中。它不起作用。 IE工作正常。



如果我把alert('');

它看起来像一个问题没有得到加载的脚本?



谢谢,
ian


我认为Document.ready在所有脚本加载并准备就绪后被解雇。



只需要一个onload函数作为如下:

 < body onload =JavascriptFunctionName> 

或者您可以动态地将您的函数调用添加到onload事件中,如下所示:

  function addEvent(obj,evType,fn){
if(obj.addEventListener){
obj.addEventListener(evType, fn,false);
返回true;
} else if(obj.attachEvent){
var r = obj.attachEvent(on+ evType,fn);
return r;
} else {
return false;


addEvent(window,'load',JavascriptFunctionName);

可以在 JavascriptFunctionName 函数。

编辑
$ b $ j jQuery也能够通过下面的代码。为了避免不必要的冗余代码,我建议首先尝试一下。

  $(window).load(function(){ 
JavascriptFunctionName();
});


In FireFox I have this jQuery at the end of the body:

$(document).ready(function() {
     $.getScript('LiveMapsJavascriptProvider.aspx?type=reference&value=6', init);
});

There are a lot of js files in the head that are needed to be all loaded before this would work. So I put my call in a document.ready event. It doesn't work. IE works fine.

If I put an alert(''); before I call $.getScript it works.

It looks like a problem with the scripts not getting loaded yet?

I thought Document.ready was fired after all the scripts are loaded and ready to go.

Thanks, ian

解决方案

You don't necessarily need to use jQuery for that.

Simply have an onload function as below:

<body onload="JavascriptFunctionName">

Or you can dynamically attach your function call to the onload event as shown below:

function addEvent(obj, evType, fn){ 
 if (obj.addEventListener){ 
   obj.addEventListener(evType, fn, false); 
   return true; 
 } else if (obj.attachEvent){ 
   var r = obj.attachEvent("on"+evType, fn); 
   return r; 
 } else { 
   return false; 
 } 
}
addEvent(window, 'load', JavascriptFunctionName);

You may embed jQuery functions calls inside the JavascriptFunctionName function.

EDIT:

jQuery is also capable of doing that through the following code. I recommend trying that first, for the sake of avoiding unnecessary redundant code.

$(window).load(function() {
    JavascriptFunctionName();
});

这篇关于javascript文档准备firefox(jQuery)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆