除非我使用alert(),否则JavaScript无法正常工作! [英] JavaScript won't work unless I use alert()!

查看:96
本文介绍了除非我使用alert(),否则JavaScript无法正常工作!的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不时遇到这个问题,但我不知道如何解决.这是我失败的代码:

I run into this issue from time to time and I don't know how to solve it. Here's my code that fails:

function on_lightbox_open() {

    system.contextBrowserInit();

    updateUrl(year + '/' + month + '/' + id);
    ads.reload();
    system.analytics.reload();

    FB.XFBML.parse($('#bottom_flap .fb_like').get(0)); // facebook
    $.ajax({ url: 'http://platform.twitter.com/widgets.js', dataType: 'script', cache: true });

    $('#lightbox .close').live('click', function(){
        $.modal.close();
    });
}

如果我像这样一开始就添加了警报:

If I add an alert at the begining like so:

function on_lightbox_open() {

    alert('i work now');

    system.contextBrowserInit();

    updateUrl(year + '/' + month + '/' + id);
    ads.reload();
    system.analytics.reload();

    FB.XFBML.parse($('#bottom_flap .fb_like').get(0)); // facebook
    $.ajax({ url: 'http://platform.twitter.com/widgets.js', dataType: 'script', cache: true });

    $('#lightbox .close').live('click', function(){
        $.modal.close();
    });
}

它神奇地起作用.如何使其在没有烦人的随机警报的情况下工作?

It magically works. How to make it work without an annoying random alert?

推荐答案

也许您对.live()的使用需要完全加载的文档,而警报只会使浏览器多花一些时间.尝试使用$(document).ready();

Perhaps your use of .live() requires a fully loaded document and the alert just buys the browser some extra time. Try surrounding with $(document).ready();

来源: jQuery驱动的应用程序.没有alert()将无法工作

这篇关于除非我使用alert(),否则JavaScript无法正常工作!的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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